/////////////////////////////////////////////////////////////////////////////// // is_callable_with_args.hpp // Contains definition of the is_callable_with_args function trait, which // determines whether a particular callable type is callable with the // specified argument types. // // Copyright 2009 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include namespace boost { namespace function_types { namespace detail { struct private_type { private_type operator,(int) const volatile; }; typedef char yes_type; // sizeof(yes_type) == 1 typedef char (&no_type)[2]; // sizeof(no_type) == 2 template no_type is_private_type(T const &); yes_type is_private_type(private_type const &); template struct funwrap : Fun { funwrap(); typedef funwrap type; typedef private_type (*pfn)(...); operator pfn() const volatile; }; template struct funwrap : Fun { funwrap(); typedef funwrap const type; typedef private_type (*pfn)(...); operator pfn() const volatile; }; template struct funwrap : Fun { funwrap(); typedef funwrap volatile type; typedef private_type (*pfn)(...); operator pfn() const volatile; }; template struct funwrap : Fun { funwrap(); typedef funwrap const volatile type; typedef private_type (*pfn)(...); operator pfn() const volatile; }; #define M0(Z, N, DATA) \ template \ struct funwrap \ { \ funwrap(); \ typedef funwrap type; \ typedef private_type (*pfn)(...); \ Ret operator()(BOOST_PP_ENUM_PARAMS_Z(Z, N, A)); \ operator pfn() const volatile; \ }; \ template \ struct funwrap \ { \ funwrap(); \ typedef funwrap type; \ typedef private_type (*pfn)(...); \ Ret operator()(BOOST_PP_ENUM_PARAMS_Z(Z, N, A)); \ operator pfn() const volatile; \ }; \ template \ struct funwrap \ { \ funwrap(); \ typedef funwrap type; \ typedef private_type (*pfn)(...); \ Ret operator()(BOOST_PP_ENUM_PARAMS_Z(Z, N, A) ...); \ operator pfn() const volatile; \ }; \ template \ struct funwrap \ { \ funwrap(); \ typedef funwrap type; \ typedef private_type (*pfn)(...); \ Ret operator()(BOOST_PP_ENUM_PARAMS_Z(Z, N, A) ...); \ operator pfn() const volatile; \ }; \ /**/ BOOST_PP_REPEAT(BOOST_FT_MAX_ARITY, M0, ~) #undef M0 template struct funwrap : funwrap {}; } template struct is_callable_with_args; #define M0(Z, N, DATA) \ static typename add_reference::type BOOST_PP_CAT(a, N); \ /**/ #define M1(Z, N, DATA) \ template \ struct is_callable_with_args \ { \ static typename detail::funwrap::type &fun; \ BOOST_PP_REPEAT_ ## Z(N, M0, ~) \ BOOST_STATIC_CONSTANT(bool, value = ( \ sizeof(detail::no_type) == sizeof( \ detail::is_private_type( (fun(BOOST_PP_ENUM_PARAMS_Z(Z, N, a)), 0) ) \ ) \ )); \ typedef mpl::bool_ type; \ }; \ /**/ BOOST_PP_REPEAT(BOOST_FT_MAX_ARITY, M1, ~) #undef M0 #undef M1 } }