Improve vacpp support.
[boost.git] / boost / boost / variant / detail / forced_return.hpp
blobcc1f25b59f3fd46b09305c855f3fd42e93bae53f
1 //-----------------------------------------------------------------------------
2 // boost variant/detail/forced_return.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
5 //
6 // Copyright (c) 2003
7 // Eric Friedman
8 //
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
14 #define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
16 #include "boost/config.hpp"
17 #include "boost/variant/detail/generic_result_type.hpp"
18 #include "boost/assert.hpp"
20 #if !defined(BOOST_MSVC) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
21 # include "boost/type_traits/remove_reference.hpp"
22 #endif
24 namespace boost {
25 namespace detail { namespace variant {
27 ///////////////////////////////////////////////////////////////////////////////
28 // (detail) function template forced_return
30 // Logical error to permit invocation at runtime, but (artificially) satisfies
31 // compile-time requirement of returning a result value.
34 #if !defined(BOOST_MSVC) \
35 && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
36 && !defined(BOOST_NO_VOID_RETURNS)
38 // "standard" implementation:
40 template <typename T>
41 inline T forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
43 // logical error: should never be here! (see above)
44 BOOST_ASSERT(false);
46 typedef typename boost::remove_reference<T>::type basic_type;
47 basic_type* dummy = 0;
48 return *static_cast< basic_type* >(dummy);
51 template <>
52 inline void forced_return<void>( BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(void) )
54 // logical error: should never be here! (see above)
55 BOOST_ASSERT(false);
58 #elif !defined(BOOST_MSVC)
60 // workaround implementation
62 // TODO: Determine the most efficient way to handle this -- as below? by
63 // throwing? by recursive call to forced_return itself? etc.
66 template <typename T>
67 inline
68 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
69 forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
71 // logical error: should never be here! (see above)
72 BOOST_ASSERT(false);
74 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) (*dummy)() = 0;
75 return dummy();
78 #else // defined(BOOST_MSVC)
80 // msvc-specific implementation
82 // Leverages __declspec(noreturn) for optimized implementation.
85 __declspec(noreturn)
86 inline void forced_return_no_return() {};
88 template <typename T>
89 inline
90 BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
91 forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
93 // logical error: should never be here! (see above)
94 BOOST_ASSERT(false);
96 forced_return_no_return();
99 #endif // BOOST_MSVC optimization
101 }} // namespace detail::variant
102 } // namespace boost
104 #endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP