summaryrefslogtreecommitdiff
path: root/boost/variant/get.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/variant/get.hpp')
-rw-r--r--boost/variant/get.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/boost/variant/get.hpp b/boost/variant/get.hpp
index f3eb84dc29..fd702ba60c 100644
--- a/boost/variant/get.hpp
+++ b/boost/variant/get.hpp
@@ -22,9 +22,11 @@
#include <boost/utility/addressof.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/variant/detail/element_index.hpp>
+#include <boost/variant/detail/move.hpp>
#include <boost/type_traits/add_reference.hpp>
#include <boost/type_traits/add_pointer.hpp>
+#include <boost/type_traits/is_lvalue_reference.hpp>
namespace boost {
@@ -170,7 +172,23 @@ relaxed_get(
return *result;
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+ U&&
+relaxed_get(
+ boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
+ BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+ )
+{
+ typedef typename add_pointer<U>::type U_ptr;
+ U_ptr result = relaxed_get<U>(boost::addressof(operand));
+ if (!result)
+ boost::throw_exception(bad_get());
+ return static_cast<U&&>(*result);
+}
+#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// strict_get<U>(variant) methods
@@ -243,6 +261,30 @@ strict_get(
return relaxed_get<U>(operand);
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+ U&&
+strict_get(
+ boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
+ BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+ )
+{
+ BOOST_STATIC_ASSERT_MSG(
+ (!boost::is_lvalue_reference<U>::value),
+ "remove ampersand '&' from template type U in boost::get<U>(boost::variant<T...>&&) "
+ );
+
+ BOOST_STATIC_ASSERT_MSG(
+ (boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, U >::value),
+ "boost::variant does not contain specified type U, "
+ "call to boost::get<U>(const boost::variant<T...>&) will always throw boost::bad_get exception"
+ );
+
+ return relaxed_get<U>(detail::variant::move(operand));
+}
+#endif
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// get<U>(variant) methods
//
@@ -308,6 +350,23 @@ get(
#endif
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+ U&&
+get(
+ boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >&& operand
+ BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+ )
+{
+#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
+ return relaxed_get<U>(detail::variant::move(operand));
+#else
+ return strict_get<U>(detail::variant::move(operand));
+#endif
+}
+#endif
+
} // namespace boost
#endif // BOOST_VARIANT_GET_HPP