1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_DETAIL_IS_INVOCABLE_HPP
10 #define BOOST_POLY_COLLECTION_DETAIL_IS_INVOCABLE_HPP
17 #include <type_traits>
19 /* technique explained at
20 * http://bannalia.blogspot.com/2016/09/compile-time-checking-existence-of.html
24 namespace poly_collection{
26 namespace is_invocable_fallback{
28 template <typename F,typename... Args>
30 std::is_constructible<
31 std::function<void(Args...)>,
32 std::reference_wrapper<typename std::remove_reference<F>::type>
36 template <typename R,typename F,typename... Args>
37 struct is_invocable_r:
38 std::is_constructible<
39 std::function<R(Args...)>,
40 std::reference_wrapper<typename std::remove_reference<F>::type>
51 struct is_void< ::boost::poly_collection::detail::is_invocable_fallback::hook>:
54 template<typename F,typename... Args>
55 static constexpr bool is_invocable_f()
57 using namespace ::boost::poly_collection::detail::is_invocable_fallback;
58 return is_invocable<F,Args...>::value;
61 template<typename R,typename F,typename... Args>
62 static constexpr bool is_invocable_r_f()
64 using namespace ::boost::poly_collection::detail::is_invocable_fallback;
65 return is_invocable_r<R,F,Args...>::value;
73 namespace poly_collection{
77 template<typename F,typename... Args>
78 struct is_invocable:std::integral_constant<
80 std::is_void<is_invocable_fallback::hook>::template
81 is_invocable_f<F,Args...>()
84 template<typename R,typename F,typename... Args>
85 struct is_invocable_r:std::integral_constant<
87 std::is_void<is_invocable_fallback::hook>::template
88 is_invocable_r_f<R,F,Args...>()
91 } /* namespace poly_collection::detail */
93 } /* namespace poly_collection */
95 } /* namespace boost */