• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2009-2016 Vladimir Batov.
2 // Use, modification and distribution are subject to the Boost Software License,
3 // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
4 
5 #ifndef BOOST_CONVERT_IS_FUNCTION_HPP
6 #define BOOST_CONVERT_IS_FUNCTION_HPP
7 
8 #include <boost/convert/detail/config.hpp>
9 #include <boost/convert/detail/has_member.hpp>
10 #include <boost/utility/enable_if.hpp>
11 #include <boost/type_traits.hpp>
12 #include <boost/function_types/is_function_pointer.hpp>
13 #include <boost/function_types/function_arity.hpp>
14 #include <boost/function_types/result_type.hpp>
15 
16 namespace boost { namespace cnv
17 {
18     typedef ::boost::type_traits::yes_type yes_type;
19     typedef ::boost::type_traits:: no_type  no_type;
20 
21     template <bool has_operator, typename Functor, typename TypeOut>
22     struct check_functor { BOOST_STATIC_CONSTANT(bool, value = false); };
23 
24     template<typename Func, typename TypeOut, class Enable =void>
25     struct is_fun { BOOST_STATIC_CONSTANT(bool, value = false); };
26 
27     template <typename Functor, typename TypeOut>
28     struct check_functor<true, Functor, TypeOut>
29     {
30         static yes_type test (TypeOut const&);
31         static no_type  test (...);
32 
33         static const bool value = sizeof(yes_type) == sizeof(test(((Functor*) 0)->operator()()));
34     };
35 
36     template<typename Functor, typename TypeOut>
37     struct is_fun<Functor, TypeOut,
38         typename enable_if_c<is_class<Functor>::value && !is_convertible<Functor, TypeOut>::value, void>::type>
39     {
40         BOOST_DECLARE_HAS_MEMBER(has_funop, operator());
41 
42         BOOST_STATIC_CONSTANT(bool, value = (check_functor<has_funop<Functor>::value, Functor, TypeOut>::value));
43     };
44 
45     template<typename Function, typename TypeOut>
46     struct is_fun<Function, TypeOut,
47         typename enable_if_c<
48             function_types::is_function_pointer<Function>::value &&
49             function_types::function_arity<Function>::value == 0 &&
50             !is_same<Function, TypeOut>::value,
51         void>::type>
52     {
53         typedef TypeOut                                                   out_type;
54         typedef typename function_types::result_type<Function>::type func_out_type;
55 
56         BOOST_STATIC_CONSTANT(bool, value = (is_convertible<func_out_type, out_type>::value));
57     };
58 }}
59 
60 #endif // BOOST_CONVERT_IS_FUNCTION_HPP
61 
62