diff DEPENDENCIES/generic/include/boost/variant/get.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/variant/get.hpp	Fri Sep 04 12:01:02 2015 +0100
+++ b/DEPENDENCIES/generic/include/boost/variant/get.hpp	Mon Sep 07 11:12:49 2015 +0100
@@ -3,8 +3,8 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 //-----------------------------------------------------------------------------
 //
-// Copyright (c) 2003
-// Eric Friedman, Itay Maman
+// Copyright (c) 2003 Eric Friedman, Itay Maman
+// Copyright (c) 2014 Antony Polukhin
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
@@ -17,19 +17,15 @@
 
 #include "boost/config.hpp"
 #include "boost/detail/workaround.hpp"
+#include "boost/static_assert.hpp"
 #include "boost/throw_exception.hpp"
 #include "boost/utility/addressof.hpp"
 #include "boost/variant/variant_fwd.hpp"
+#include "boost/variant/detail/element_index.hpp"
 
 #include "boost/type_traits/add_reference.hpp"
 #include "boost/type_traits/add_pointer.hpp"
 
-#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
-#   include "boost/mpl/bool.hpp"
-#   include "boost/mpl/or.hpp"
-#   include "boost/type_traits/is_same.hpp"
-#endif
-
 namespace boost {
 
 //////////////////////////////////////////////////////////////////////////
@@ -37,7 +33,7 @@
 //
 // The exception thrown in the event of a failed get of a value.
 //
-class bad_get
+class BOOST_SYMBOL_VISIBLE bad_get
     : public std::exception
 {
 public: // std::exception implementation
@@ -78,71 +74,39 @@
 
 public: // visitor interfaces
 
-#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
-
-    pointer operator()(reference operand) const
+    pointer operator()(reference operand) const BOOST_NOEXCEPT
     {
         return boost::addressof(operand);
     }
 
     template <typename U>
-    pointer operator()(const U&) const
+    pointer operator()(const U&) const BOOST_NOEXCEPT
     {
         return static_cast<pointer>(0);
     }
-
-#else // MSVC6
-
-private: // helpers, for visitor interfaces (below)
-
-    pointer execute_impl(reference operand, mpl::true_) const
-    {
-        return boost::addressof(operand);
-    }
-
-    template <typename U>
-    pointer execute_impl(const U& operand, mpl::false_) const
-    {
-        return static_cast<pointer>(0);
-    }
-
-public: // visitor interfaces
-
-    template <typename U>
-    pointer operator()(U& operand) const
-    {
-        // MSVC6 finds normal implementation (above) ambiguous,
-        // so we must explicitly disambiguate
-
-        typedef typename mpl::or_<
-              is_same<U, T>
-            , is_same<const U, T>
-            >::type U_is_T;
-
-        return execute_impl(operand, U_is_T());
-    }
-
-#endif // MSVC6 workaround
-
 };
 
 }} // namespace detail::variant
 
-#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
-#   define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)  \
-    BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(t)
-#else
-#   define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)  \
-    , t* = 0
+#ifndef BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE
+#   if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
+#       define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)
+#   else
+#       define BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(t)  \
+        , t* = 0
+#   endif
 #endif
 
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// relaxed_get<U>(variant) methods
+//
 template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
 inline
     typename add_pointer<U>::type
-get(
+relaxed_get(
       boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
       BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
-    )
+    ) BOOST_NOEXCEPT
 {
     typedef typename add_pointer<U>::type U_ptr;
     if (!operand) return static_cast<U_ptr>(0);
@@ -154,10 +118,10 @@
 template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
 inline
     typename add_pointer<const U>::type
-get(
+relaxed_get(
       const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
       BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
-    )
+    ) BOOST_NOEXCEPT
 {
     typedef typename add_pointer<const U>::type U_ptr;
     if (!operand) return static_cast<U_ptr>(0);
@@ -169,17 +133,156 @@
 template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
 inline
     typename add_reference<U>::type
+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>(&operand);
+
+    if (!result)
+        boost::throw_exception(bad_get());
+    return *result;
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_reference<const U>::type
+relaxed_get(
+      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    )
+{
+    typedef typename add_pointer<const U>::type U_ptr;
+    U_ptr result = relaxed_get<const U>(&operand);
+
+    if (!result)
+        boost::throw_exception(bad_get());
+    return *result;
+}
+
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// strict_get<U>(variant) methods
+//
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_pointer<U>::type
+strict_get(
+      boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    ) BOOST_NOEXCEPT
+{
+    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>(boost::variant<T...>*) will always return NULL"
+    );
+
+    return relaxed_get<U>(operand);
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_pointer<const U>::type
+strict_get(
+      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    ) BOOST_NOEXCEPT
+{
+    BOOST_STATIC_ASSERT_MSG(
+        (boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, const U >::value),
+        "boost::variant does not contain specified type U, "
+        "call to boost::get<U>(const boost::variant<T...>*) will always return NULL"
+    );
+
+    return relaxed_get<U>(operand);
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_reference<U>::type
+strict_get(
+      boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    )
+{
+    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>(boost::variant<T...>&) will always throw boost::bad_get exception"
+    );
+
+    return relaxed_get<U>(operand);
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_reference<const U>::type
+strict_get(
+      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    )
+{
+    BOOST_STATIC_ASSERT_MSG(
+        (boost::detail::variant::holds_element<boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >, const 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>(operand);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// get<U>(variant) methods
+//
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_pointer<U>::type
+get(
+      boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    ) BOOST_NOEXCEPT
+{
+#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
+    return relaxed_get<U>(operand);
+#else
+    return strict_get<U>(operand);
+#endif
+
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_pointer<const U>::type
+get(
+      const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
+      BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
+    ) BOOST_NOEXCEPT
+{
+#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
+    return relaxed_get<U>(operand);
+#else
+    return strict_get<U>(operand);
+#endif
+}
+
+template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
+inline
+    typename add_reference<U>::type
 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 = get<U>(&operand);
-
-    if (!result)
-        boost::throw_exception(bad_get());
-    return *result;
+#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
+    return relaxed_get<U>(operand);
+#else
+    return strict_get<U>(operand);
+#endif
 }
 
 template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
@@ -190,12 +293,11 @@
       BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
     )
 {
-    typedef typename add_pointer<const U>::type U_ptr;
-    U_ptr result = get<const U>(&operand);
-
-    if (!result)
-        boost::throw_exception(bad_get());
-    return *result;
+#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
+    return relaxed_get<U>(operand);
+#else
+    return strict_get<U>(operand);
+#endif
 }
 
 } // namespace boost