2 @Copyright Barrett Adair 2016-2017
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_CLBL_TRTS_SFINAE_ERRORS_HPP
10 #define BOOST_CLBL_TRTS_SFINAE_ERRORS_HPP
12 #include <boost/callable_traits/detail/config.hpp>
14 namespace boost { namespace callable_traits { namespace detail {
16 struct sfinae_error{};
20 static constexpr bool value = true;
21 struct _ { using type = T; };
24 template<bool B, typename T>
26 static_assert(std::is_base_of<sfinae_error, T>::value,
27 "incorrect usage of fail_if");
29 static constexpr bool value = B;
32 template<typename T, typename... FailIfs>
33 using sfinae_try = typename BOOST_CLBL_TRTS_DISJUNCTION(
34 FailIfs..., success<T>)::_::type;
36 template<typename FailMsg, typename ForceTwoPhaseLookup>
38 using type = typename std::conditional<std::is_same<ForceTwoPhaseLookup, std::false_type>::value,
39 FailMsg, FailMsg>::type::_::type;
42 }}} // namespace boost::callable_traits::detail
44 #define BOOST_CLBL_TRTS_PP_CAT_(x, y) x ## y
45 #define BOOST_CLBL_TRTS_PP_CAT(x, y) BOOST_CLBL_TRTS_PP_CAT_(x, y)
47 #define BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(origin) \
49 template<typename ErrorMessage> \
51 ::boost::callable_traits::detail::sfinae_error \
56 #define BOOST_CLBL_TRTS_SFINAE_MSG(origin, name) \
57 struct BOOST_CLBL_TRTS_PP_CAT(name, _ ){}; \
58 struct name : error::origin< \
59 BOOST_CLBL_TRTS_PP_CAT(name, _ )>{}; \
62 namespace boost { namespace callable_traits {
64 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(parameters)
65 BOOST_CLBL_TRTS_SFINAE_MSG(parameters, index_out_of_range_for_parameter_list)
66 BOOST_CLBL_TRTS_SFINAE_MSG(parameters, cannot_determine_parameters_for_this_type)
68 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(varargs)
69 BOOST_CLBL_TRTS_SFINAE_MSG(varargs, varargs_are_illegal_for_this_type)
71 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(member_qualifiers)
72 BOOST_CLBL_TRTS_SFINAE_MSG(member_qualifiers, member_qualifiers_are_illegal_for_this_type)
73 BOOST_CLBL_TRTS_SFINAE_MSG(member_qualifiers, this_compiler_doesnt_support_abominable_function_types)
75 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(transaction_safe_)
76 BOOST_CLBL_TRTS_SFINAE_MSG(transaction_safe_, transaction_safe_is_not_supported_by_this_configuration)
78 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(expand_args)
79 BOOST_CLBL_TRTS_SFINAE_MSG(expand_args, cannot_expand_the_parameter_list_of_first_template_argument)
81 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(member_pointer_required)
82 BOOST_CLBL_TRTS_SFINAE_MSG(member_pointer_required, type_is_not_a_member_pointer)
84 BOOST_CLBL_TRTS_DEFINE_SFINAE_ERROR_ORIGIN(reference_error)
85 BOOST_CLBL_TRTS_SFINAE_MSG(reference_error, reference_type_not_supported_by_this_metafunction)
87 }} // namespace boost::callable_traits
89 #endif // #ifndef BOOST_CLBL_TRTS_SFINAE_ERRORS_HPP