File indexing completed on 2025-01-18 09:38:14
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_HOF_GUARD_FUNCTION_DELGATE_H
0009 #define BOOST_HOF_GUARD_FUNCTION_DELGATE_H
0010
0011 #include <type_traits>
0012 #include <utility>
0013 #include <boost/hof/config.hpp>
0014 #include <boost/hof/detail/and.hpp>
0015 #include <boost/hof/detail/holder.hpp>
0016 #include <boost/hof/detail/forward.hpp>
0017 #include <boost/hof/detail/using.hpp>
0018 #include <boost/hof/detail/intrinsics.hpp>
0019 #include <boost/hof/detail/noexcept.hpp>
0020
0021
0022 #define BOOST_HOF_ENABLE_IF_CONVERTIBLE(...) \
0023 class=typename std::enable_if<BOOST_HOF_IS_CONVERTIBLE(__VA_ARGS__)>::type
0024
0025 #define BOOST_HOF_ENABLE_IF_CONVERTIBLE_UNPACK(...) \
0026 class=typename std::enable_if<BOOST_HOF_AND_UNPACK(BOOST_HOF_IS_CONVERTIBLE(__VA_ARGS__))>::type
0027
0028 #define BOOST_HOF_ENABLE_IF_BASE_OF(...) \
0029 class=typename std::enable_if<BOOST_HOF_IS_BASE_OF(__VA_ARGS__)>::type
0030
0031 #define BOOST_HOF_ENABLE_IF_CONSTRUCTIBLE(...) \
0032 class=typename std::enable_if<BOOST_HOF_IS_CONSTRUCTIBLE(__VA_ARGS__)>::type
0033
0034 #define BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(...) \
0035 BOOST_HOF_NOEXCEPT(BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(__VA_ARGS__))
0036
0037 #define BOOST_HOF_INHERIT_DEFAULT(C, ...) \
0038 template<bool FitPrivateEnableBool_##__LINE__=true, \
0039 class=typename std::enable_if<FitPrivateEnableBool_##__LINE__ && boost::hof::detail::is_default_constructible_c<__VA_ARGS__>()>::type> \
0040 constexpr C() BOOST_HOF_NOEXCEPT(boost::hof::detail::is_nothrow_default_constructible_c<__VA_ARGS__>()) {}
0041
0042 #define BOOST_HOF_INHERIT_DEFAULT_EMPTY(C, ...) \
0043 template<bool FitPrivateEnableBool_##__LINE__=true, \
0044 class=typename std::enable_if<FitPrivateEnableBool_##__LINE__ && \
0045 boost::hof::detail::is_default_constructible_c<__VA_ARGS__>() && BOOST_HOF_IS_EMPTY(__VA_ARGS__) \
0046 >::type> \
0047 constexpr C() BOOST_HOF_NOEXCEPT(boost::hof::detail::is_nothrow_default_constructible_c<__VA_ARGS__>()) {}
0048
0049 #if BOOST_HOF_NO_TYPE_PACK_EXPANSION_IN_TEMPLATE
0050
0051 #define BOOST_HOF_DELGATE_PRIMITIVE_CONSTRUCTOR(constexpr_, C, T, var) \
0052 template<class... FitXs, typename boost::hof::detail::enable_if_constructible<C, T, FitXs...>::type = 0> \
0053 constexpr_ C(FitXs&&... fit_xs) \
0054 BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(T, FitXs&&...) \
0055 : var((FitXs&&)boost::hof::forward<FitXs>(fit_xs)...) {}
0056
0057 #else
0058 #define BOOST_HOF_DELGATE_PRIMITIVE_CONSTRUCTOR(constexpr_, C, T, var) \
0059 template<class... FitXs, BOOST_HOF_ENABLE_IF_CONSTRUCTIBLE(T, FitXs&&...)> \
0060 constexpr_ C(FitXs&&... fit_xs) \
0061 BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(T, FitXs&&...) \
0062 : var(BOOST_HOF_FORWARD(FitXs)(fit_xs)...) {}
0063
0064 #endif
0065
0066 #define BOOST_HOF_DELEGATE_CONSTRUCTOR(C, T, var) BOOST_HOF_DELGATE_PRIMITIVE_CONSTRUCTOR(constexpr, C, T, var)
0067
0068
0069
0070 #if 1
0071 #define BOOST_HOF_INHERIT_CONSTRUCTOR(Derived, Base) BOOST_HOF_DELEGATE_CONSTRUCTOR(Derived, Base, Base)
0072 #else
0073 #define BOOST_HOF_INHERIT_CONSTRUCTOR(Derived, Base) \
0074 using fit_inherit_base = Base; \
0075 using fit_inherit_base::fit_inherit_base; \
0076 Derived()=default; \
0077 template<class FitX, BOOST_HOF_ENABLE_IF_CONVERTIBLE(FitX, Base)> \
0078 constexpr Derived(FitX&& fit_x) : Base(BOOST_HOF_FORWARD(FitX)(fit_x)) {}
0079 #endif
0080
0081 namespace boost { namespace hof {
0082 namespace detail {
0083
0084 template<class... Xs>
0085 constexpr bool is_nothrow_default_constructible_c()
0086 {
0087 return BOOST_HOF_AND_UNPACK(BOOST_HOF_IS_NOTHROW_CONSTRUCTIBLE(Xs));
0088 }
0089
0090 template<class... Xs>
0091 constexpr bool is_default_constructible_c()
0092 {
0093 return BOOST_HOF_AND_UNPACK(BOOST_HOF_IS_DEFAULT_CONSTRUCTIBLE(Xs));
0094 }
0095
0096 template<class... Xs>
0097 BOOST_HOF_USING(is_default_constructible, std::integral_constant<bool, is_default_constructible_c<Xs...>()>);
0098
0099 template<class C, class X, class... Xs>
0100 struct enable_if_constructible
0101 : std::enable_if<is_constructible<X, Xs&&...>::value, int>
0102 {};
0103
0104 }
0105 }}
0106
0107 #endif