Commit 16d30bbd by Jonathan Wakely Committed by Jonathan Wakely

PR libstdc++/87431 optimise valueless_by_exception()

If a std::variant can never get into valueless state then we don't need
to do a runtime check for a valid alternative.

	PR libstdc++/87431
	* include/std/variant (_Variant_storage<true, _Types...>::_M_valid):
	Avoid runtime test when all alternatives are scalars and so cannot
	throw during initialization.

From-SVN: r264574
parent 4fb792e1
2018-09-25 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/87431
* include/std/variant (_Variant_storage<true, _Types...>::_M_valid):
Avoid runtime test when all alternatives are scalars and so cannot
throw during initialization.
2018-09-25 Gerald Pfeifer <gerald@pfeifer.com> 2018-09-25 Gerald Pfeifer <gerald@pfeifer.com>
* doc/xml/manual/codecvt.xml: Move link to "UTF-8 and Unicode FAQ" * doc/xml/manual/codecvt.xml: Move link to "UTF-8 and Unicode FAQ"
......
...@@ -439,6 +439,8 @@ namespace __variant ...@@ -439,6 +439,8 @@ namespace __variant
constexpr bool constexpr bool
_M_valid() const noexcept _M_valid() const noexcept
{ {
if constexpr ((is_scalar_v<_Types> && ...))
return true;
return this->_M_index != __index_type(variant_npos); return this->_M_index != __index_type(variant_npos);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment