1 /*=============================================================================
2 Copyright (c) 2015 Paul Fultz II
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
8 #ifndef BOOST_HOF_GUARD_FUNCTION_CONSTEXPR_DEDUCE_H
9 #define BOOST_HOF_GUARD_FUNCTION_CONSTEXPR_DEDUCE_H
11 #include <boost/hof/config.hpp>
13 #define BOOST_HOF_CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
15 #ifndef BOOST_HOF_HAS_CONST_FOLD
16 #if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
17 #define BOOST_HOF_HAS_CONST_FOLD 0
18 #elif defined(__clang__) || defined (__GNUC__)
19 #define BOOST_HOF_HAS_CONST_FOLD 1
21 #define BOOST_HOF_HAS_CONST_FOLD 0
26 namespace boost { namespace hof {
30 struct constexpr_deduce
32 constexpr constexpr_deduce()
35 constexpr operator F() const
42 struct constexpr_deduce_unique
44 constexpr constexpr_deduce_unique()
46 #if BOOST_HOF_HAS_CONST_FOLD
48 constexpr operator const F&() const
50 static_assert(BOOST_HOF_IS_EMPTY(F), "Function or lambda expression must be empty");
51 return BOOST_HOF_CONST_FOLD(reinterpret_cast<const F&>(static_const_var<T>()));
55 constexpr operator F() const
57 // static_assert(std::is_default_constructible<F>::value, "Function not default constructible");
63 }}} // namespace boost::hof
65 #define BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE true ? boost::hof::detail::constexpr_deduce() :
66 #define BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE_UNIQUE(T) true ? boost::hof::detail::constexpr_deduce_unique<T>() :
69 #define BOOST_HOF_DETAIL_MSVC_CONSTEXPR_DEDUCE BOOST_HOF_DETAIL_CONSTEXPR_DEDUCE
71 #define BOOST_HOF_DETAIL_MSVC_CONSTEXPR_DEDUCE