Is it possible to use a
<std::regex
object in multiple threads all usingstd::sregex_iterator
,std::regex_match
, etc.?
Yes, a const std::regex
is thread-safe. Actually any const method in the standard library is thread-safe, see:
§17.6.5.9/3. A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non-const arguments, including this.