2016-08-24 3 views
1

なぜ次のコードでstd::bad_cast例外が生成されますか?便宜上basic_regexがchar32_tでbad_castをスローします

#include <iostream> 
#include <regex> 
#include <string> 

int main() 
{ 
    std::basic_string<char32_t> reg = U"^\\w"; 

    try 
    { 
     std::basic_regex<char32_t> tagRegex(reg); 
    } 
    catch(std::exception &e) 
    { 
     std::cout << e.what() << std::endl; 
    } 

    return 0; 
} 

Ideoneにこのサンプルは:https://ideone.com/Saea88

(プルーフ:https://ideone.com/OBlXed)も投げることなく、代わりchar32_tランのchar又はwcharを使用します。

答えて

2

あなたがここに見つけることができます:http://en.cppreference.com/w/cpp/regex/regex_traitsを:

は、(例えば、char32_t)他の文字タイプとのstd ::のbasic_regexを使用するには、ユーザー提供の形質クラスを使用する必要があります。

ので、あなたはstd::regex_traits<char32_t>

を実装するために、それはここで見るための定義が存在しない理由を参照してくださいする必要があります:Why is there no definition for std::regex_traits<char32_t> (and thus no std::basic_regex<char32_t>) provided?

関連する問題