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_CAN_BE_CALLED_H
9 #define BOOST_HOF_GUARD_CAN_BE_CALLED_H
11 #include <boost/hof/config.hpp>
12 #include <boost/hof/detail/and.hpp>
13 #include <boost/hof/detail/holder.hpp>
14 #include <boost/hof/detail/using.hpp>
16 namespace boost { namespace hof { namespace detail {
18 #if BOOST_HOF_NO_EXPRESSION_SFINAE
27 typedef dont_care type;
30 struct cant_be_called_type
37 struct is_callable_wrapper_fallback
40 auto operator()(Ts&&...) const
41 -> decltype(std::declval<F>()(std::declval<Ts>()...));
44 template<class T, class U=typename std::remove_cv<typename std::remove_reference<T>::type>::type>
45 struct is_callable_wrapper_base
46 : std::conditional<BOOST_HOF_IS_CLASS(U) && !BOOST_HOF_IS_FINAL(U), U, is_callable_wrapper_fallback<U>>
49 template<class F, class... Ts>
50 struct is_callable_wrapper : is_callable_wrapper_base<F>::type
52 is_callable_wrapper();
53 typedef cant_be_called_type const &(*pointer_to_function)(typename never_care<Ts>::type...);
54 operator pointer_to_function() const;
59 : std::integral_constant<bool, !T::value>
62 template<class F, class... Ts>
64 : not_<std::is_same<cant_be_called_type, typename std::decay<decltype(
65 is_callable_wrapper<F, Ts...>()(std::declval<Ts>()...)
69 template<class F, class... Ts>
72 template<class Res, class... Ts, class... Us>
73 struct check_args<Res(Us...), Ts...>
74 : and_<std::is_convertible<Ts, Us>...>
77 template<class Res, class... Ts, class... Us>
78 struct can_be_called<Res(*)(Us...), Ts...>
79 : std::conditional<sizeof...(Ts) == sizeof...(Us),
80 check_args<Res(Us...), Ts...>,
85 template<class Res, class... Ts, class... Us>
86 struct can_be_called<Res(Us...), Ts...>
87 : std::conditional<sizeof...(Ts) == sizeof...(Us),
88 check_args<Res(Us...), Ts...>,
96 T&& called_val() noexcept;
102 template<class F, class Args, class=void>
103 struct can_be_called_impl
107 template<class F, class... Args>
108 struct can_be_called_impl<F, callable_args<Args...>, typename detail::holder<
109 decltype( boost::hof::detail::called_val<F>()(boost::hof::detail::called_val<Args>()...) )
114 template<class F, class... Ts>
115 BOOST_HOF_USING(can_be_called, can_be_called_impl<F, detail::callable_args<Ts...>>);
119 }}} // namespace boost::hof