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