2 #ifndef BOOST_CONTRACT_DETAIL_MIRROR_HPP_
3 #define BOOST_CONTRACT_DETAIL_MIRROR_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
10 #include <boost/contract/detail/name.hpp>
11 #include <boost/function_types/member_function_pointer.hpp>
12 #include <boost/function_types/function_pointer.hpp>
13 #include <boost/function_types/property_tags.hpp>
14 #include <boost/mpl/push_front.hpp>
15 #include <boost/mpl/bool.hpp>
16 #include <boost/preprocessor/control/iif.hpp>
17 #include <boost/preprocessor/tuple/rem.hpp>
18 #include <boost/preprocessor/tuple/eat.hpp>
20 // NOTE: Unfortunately, it is not possible to use Boost.TTI because it not
21 // always works on MSVC (e.g., when the mirror meta-function is invoked
22 // multiple times, MSVC 2010 gives an internal compiler error). This is a
23 // simpler mirror implementation that seems to work better on MSVC.
27 #define BOOST_CONTRACT_DETAIL_MIRROR_END_(tparam) \
29 static boost::contract::detail::mirror::no& apply(...); \
31 static bool const value = sizeof(apply<tparam>(0)) == \
32 sizeof(boost::contract::detail::mirror::yes); \
33 typedef boost::mpl::bool_<value> type;
35 #define BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_(is_static, \
38 typename BOOST_CONTRACT_DETAIL_NAME1(T), \
39 typename BOOST_CONTRACT_DETAIL_NAME1(R), \
40 class BOOST_CONTRACT_DETAIL_NAME1(P), \
41 class BOOST_CONTRACT_DETAIL_NAME1(G) = boost::function_types::null_tag \
44 template<class BOOST_CONTRACT_DETAIL_NAME1(C)> \
45 static boost::contract::detail::mirror::yes& apply( \
46 boost::contract::detail::mirror::check_function< \
48 BOOST_PP_IIF(is_static, \
49 boost::function_types::function_pointer \
51 boost::function_types::member_function_pointer \
54 typename boost::mpl::push_front< \
55 BOOST_PP_IIF(is_static, \
56 BOOST_CONTRACT_DETAIL_NAME1(P) \
57 BOOST_PP_TUPLE_EAT(2) \
59 BOOST_PP_TUPLE_REM(2) \
61 typename boost::mpl::push_front< \
62 BOOST_CONTRACT_DETAIL_NAME1(P), \
63 BOOST_CONTRACT_DETAIL_NAME1(C) \
66 , BOOST_CONTRACT_DETAIL_NAME1(R) \
68 BOOST_CONTRACT_DETAIL_NAME1(G) \
70 &BOOST_CONTRACT_DETAIL_NAME1(C)::func_name \
73 BOOST_CONTRACT_DETAIL_MIRROR_END_( \
74 BOOST_CONTRACT_DETAIL_NAME1(T)) \
79 #define BOOST_CONTRACT_DETAIL_MIRROR_HAS_TYPE(trait, type_name)\
80 template<typename BOOST_CONTRACT_DETAIL_NAME1(T)> \
82 template<class BOOST_CONTRACT_DETAIL_NAME1(C)> \
83 static boost::contract::detail::mirror::yes& apply( \
84 typename BOOST_CONTRACT_DETAIL_NAME1(C)::type_name*); \
85 BOOST_CONTRACT_DETAIL_MIRROR_END_( \
86 BOOST_CONTRACT_DETAIL_NAME1(T)) \
89 #define BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \
91 BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_( \
92 /* is_static = */ 0, trait, func_name)
94 #define BOOST_CONTRACT_DETAIL_MIRROR_HAS_STATIC_MEMBER_FUNCTION(trait, \
96 BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_( \
97 /* is_static = */ 1, trait, func_name)
101 namespace boost { namespace contract { namespace detail { namespace mirror {
103 typedef class {} yes;
106 template<typename F, F> class check_function;
110 #endif // #include guard