Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:56:46

0001 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/poly_collection for library home page.
0007  */
0008 
0009 #ifndef BOOST_POLY_COLLECTION_DETAIL_IS_INVOCABLE_HPP
0010 #define BOOST_POLY_COLLECTION_DETAIL_IS_INVOCABLE_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 #include <functional>
0017 #include <type_traits>
0018 
0019 /* technique explained at
0020  * http://bannalia.blogspot.com/2016/09/compile-time-checking-existence-of.html 
0021  */
0022 
0023 namespace boost{
0024 namespace poly_collection{
0025 namespace detail{
0026 namespace is_invocable_fallback{
0027 
0028 template <typename F,typename... Args>
0029 struct is_invocable:
0030   std::is_constructible<
0031     std::function<void(Args...)>,
0032     std::reference_wrapper<typename std::remove_reference<F>::type>
0033   >
0034 {};
0035 
0036 template <typename R,typename F,typename... Args>
0037 struct is_invocable_r:
0038   std::is_constructible<
0039     std::function<R(Args...)>,
0040     std::reference_wrapper<typename std::remove_reference<F>::type>
0041   >
0042 {};
0043 
0044 struct hook{};
0045 
0046 }}}}
0047 
0048 namespace std{
0049 
0050 template<>
0051 struct is_void< ::boost::poly_collection::detail::is_invocable_fallback::hook>:
0052   std::false_type
0053 {      
0054   template<typename F,typename... Args>
0055   static constexpr bool is_invocable_f()
0056   {
0057     using namespace ::boost::poly_collection::detail::is_invocable_fallback;
0058     return is_invocable<F,Args...>::value;
0059   }
0060 
0061   template<typename R,typename F,typename... Args>
0062   static constexpr bool is_invocable_r_f()
0063   {
0064     using namespace ::boost::poly_collection::detail::is_invocable_fallback;
0065     return is_invocable_r<R,F,Args...>::value;
0066   }
0067 };
0068 
0069 } /* namespace std */
0070 
0071 namespace boost{
0072 
0073 namespace poly_collection{
0074 
0075 namespace detail{
0076 
0077 template<typename F,typename... Args>
0078 struct is_invocable:std::integral_constant<
0079   bool,
0080   std::is_void<is_invocable_fallback::hook>::template
0081     is_invocable_f<F,Args...>()
0082 >{};
0083 
0084 template<typename R,typename F,typename... Args>
0085 struct is_invocable_r:std::integral_constant<
0086   bool,
0087   std::is_void<is_invocable_fallback::hook>::template
0088     is_invocable_r_f<R,F,Args...>()
0089 >{};
0090 
0091 } /* namespace poly_collection::detail */
0092 
0093 } /* namespace poly_collection */
0094 
0095 } /* namespace boost */
0096 
0097 #endif