我可以在 char16_t 的字符串上使用 STL 正则表达式库吗?
Can I use the STL regex library on strings of char16_t?
简而言之,下面的代码有什么本质上的错误?
#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.
C++ 标准库不支持使用 char16_t 或 char32_t Unicode 的正则表达式。有一个解决这个问题的提议,但它不在 C++20 中:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html
简而言之,下面的代码有什么本质上的错误?
#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.
C++ 标准库不支持使用 char16_t 或 char32_t Unicode 的正则表达式。有一个解决这个问题的提议,但它不在 C++20 中:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html