Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:14

0001 /*=============================================================================
0002     Copyright (c) 2015 Paul Fultz II
0003     constexpr_deduce.h
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 
0008 #ifndef BOOST_HOF_GUARD_FUNCTION_CONSTEXPR_DEDUCE_H
0009 #define BOOST_HOF_GUARD_FUNCTION_CONSTEXPR_DEDUCE_H
0010 
0011 #include <boost/hof/config.hpp>
0012 
0013 #define BOOST_HOF_CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
0014 
0015 #ifndef BOOST_HOF_HAS_CONST_FOLD
0016 #if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
0017 #define BOOST_HOF_HAS_CONST_FOLD 0
0018 #elif defined(__clang__) || defined (__GNUC__)
0019 #define BOOST_HOF_HAS_CONST_FOLD 1
0020 #else
0021 #define BOOST_HOF_HAS_CONST_FOLD 0
0022 #endif
0023 #endif
0024 
0025 
0026 namespace boost { namespace hof {
0027 
0028 namespace detail {
0029 
0030 struct constexpr_deduce
0031 {
0032     constexpr constexpr_deduce()
0033     {}
0034     template<class F>
0035     constexpr operator F() const
0036     {
0037         return F();
0038     }
0039 };
0040 
0041 template<class T>
0042 struct constexpr_deduce_unique
0043 {
0044     constexpr constexpr_deduce_unique()
0045     {}
0046 #if BOOST_HOF_HAS_CONST_FOLD
0047     template<class F>
0048     constexpr operator const F&() const
0049     {
0050         static_assert(BOOST_HOF_IS_EMPTY(F), "Function or lambda expression must be empty");
0051         return BOOST_HOF_CONST_FOLD(reinterpret_cast<const F&>(static_const_var<T>()));
0052     }
0053 #else
0054     template<class F>
0055     constexpr operator F() const
0056     {
0057         // static_assert(std::is_default_constructible<F>::value, "Function not default constructible");
0058         return F();
0059     }
0060 #endif
0061 };
0062 
0063 }}} // namespace boost::hof
0064 
0065 #define BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE true ? boost::hof::detail::constexpr_deduce() :
0066 #define BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE_UNIQUE(T) true ? boost::hof::detail::constexpr_deduce_unique<T>() :
0067 
0068 #ifdef _MSC_VER
0069 #define BOOST_HOF_DETAIL_MSVC_CONSTEXPR_DEDUCE BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE
0070 #else
0071 #define BOOST_HOF_DETAIL_MSVC_CONSTEXPR_DEDUCE
0072 #endif
0073 
0074 #endif