PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/variant/detail/forced_return.hpp

http://hadesmem.googlecode.com/
C++ Header | 104 lines | 51 code | 22 blank | 31 comment | 3 complexity | 62188f87dea47d3b73ba75d57857f3b7 MD5 | raw file
  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)
 12
 13#ifndef BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
 14#define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
 15
 16#include "boost/config.hpp"
 17#include "boost/variant/detail/generic_result_type.hpp"
 18#include "boost/assert.hpp"
 19
 20#if !defined(BOOST_MSVC) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
 21#   include "boost/type_traits/remove_reference.hpp"
 22#endif
 23
 24namespace boost {
 25namespace detail { namespace variant {
 26
 27///////////////////////////////////////////////////////////////////////////////
 28// (detail) function template forced_return
 29//
 30// Logical error to permit invocation at runtime, but (artificially) satisfies
 31// compile-time requirement of returning a result value.
 32//
 33
 34#if !defined(BOOST_MSVC)                                \
 35 && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)  \
 36 && !defined(BOOST_NO_VOID_RETURNS)
 37
 38// "standard" implementation:
 39
 40template <typename T>
 41inline T forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
 42{
 43    // logical error: should never be here! (see above)
 44    BOOST_ASSERT(false);
 45
 46    typedef typename boost::remove_reference<T>::type basic_type;
 47    basic_type* dummy = 0;
 48    return *static_cast< basic_type* >(dummy);
 49}
 50
 51template <>
 52inline void forced_return<void>( BOOST_EXPLICIT_TEMPLATE_TYPE_SPEC(void) )
 53{
 54    // logical error: should never be here! (see above)
 55    BOOST_ASSERT(false);
 56}
 57
 58#elif !defined(BOOST_MSVC)
 59
 60// workaround implementation
 61//
 62// TODO: Determine the most efficient way to handle this -- as below? by
 63// throwing? by recursive call to forced_return itself? etc.
 64//
 65
 66template <typename T>
 67inline
 68    BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
 69forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
 70{
 71    // logical error: should never be here! (see above)
 72    BOOST_ASSERT(false);
 73
 74    BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) (*dummy)() = 0;
 75    return dummy();
 76}
 77
 78#else // defined(BOOST_MSVC)
 79
 80// msvc-specific implementation
 81//
 82// Leverages __declspec(noreturn) for optimized implementation.
 83//
 84
 85__declspec(noreturn)
 86inline void forced_return_no_return() {};
 87
 88template <typename T>
 89inline
 90    BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
 91forced_return( BOOST_EXPLICIT_TEMPLATE_TYPE(T) )
 92{
 93    // logical error: should never be here! (see above)
 94    BOOST_ASSERT(false);
 95
 96    forced_return_no_return();
 97}
 98
 99#endif // BOOST_MSVC optimization
100
101}} // namespace detail::variant
102} // namespace boost
103
104#endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP