2

简而言之,下面的代码有什么本质上的错误?

#include <regex>
int main() {
    std::regex_match(u" ", std::basic_regex<char16_t>{u" "});
}

它与

$ g++ -std=c++17 main.cpp -o main
$ ./main
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Aborted (core dumped)

更多信息:

$ g++ --version                                                                                                                                                                                                                                    
g++ (GCC) 10.2.0                                                                                                                                                                                                                                               
Copyright (C) 2020 Free Software Foundation, Inc.                                                                                                                                                                                                              
This is free software; see the source for copying conditions.  There is NO                                                                                                                                                                                     
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4

1 回答 1

2

C++ 标准库不支持 char16_t 或 char32_t Unicode 的正则表达式。有一个解决这个问题的提议,但它不在 C++20 中:http ://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html

于 2020-09-22T10:02:23.947 回答