The move constructors for stop_source and stop_token are equivalent to
copying and clearing the raw pointer, as they are wrappers for a
counted-shared state.
For jthread, the move constructor performs a member-wise move of stop_source
and thread. While std::thread could also have a _Never_valueless_alt
specialization due to its inexpensive move (only moving a handle), doing
so now would change the ABI. This patch takes the opportunity to correct
this behavior for jthread, before C++20 API is marked stable.
libstdc++-v3/ChangeLog:
* include/std/stop_token (__variant::_Never_valueless_alt): Declare.
(__variant::_Never_valueless_alt<std::stop_token>)
(__variant::_Never_valueless_alt<std::stop_source>): Define.
* include/std/thread: (__variant::_Never_valueless_alt): Declare.
(__variant::_Never_valueless_alt<std::jthread>): Define.
template<typename _Callback>
stop_callback(stop_token, _Callback) -> stop_callback<_Callback>;
+ /// @cond undocumented
+ namespace __detail::__variant
+ {
+ template<typename> struct _Never_valueless_alt; // see <variant>
+
+ // Provide the strong exception-safety guarantee when emplacing a
+ // stop_token or stop_source into a variant.
+ template<>
+ struct _Never_valueless_alt<std::stop_token>
+ : true_type
+ { };
+
+ template<>
+ struct _Never_valueless_alt<std::stop_source>
+ : true_type
+ { };
+ } // namespace __detail::__variant
+ /// @endcond
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std
#endif // __glibcxx_jthread
stop_source _M_stop_source;
thread _M_thread;
};
+
+ /// @cond undocumented
+ namespace __detail::__variant
+ {
+ template<typename> struct _Never_valueless_alt; // see <variant>
+
+ // Provide the strong exception-safety guarantee when emplacing a
+ // jthread into a variant.
+ template<>
+ struct _Never_valueless_alt<std::jthread>
+ : true_type
+ { };
+ } // namespace __detail::__variant
+ /// @endcond
#endif // __cpp_lib_jthread
#ifdef __cpp_lib_formatters // C++ >= 23