简体   繁体   中英

Can I use the STL regex library on strings of char16_t?

In short, what is inherently wrong with the following code?

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

It errors with

$ 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)

More info:

$ 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.

The C++ standard library does not support regex with char16_t or char32_t Unicode. There is a proposal to address this, but it is not in C++20: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0169r0.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM