1 2 // (C) Copyright Edward Diener 2011,2012,2013 3 // Use, modification and distribution are subject to the Boost Software License, 4 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt). 6 7 #if !defined(BOOST_TTI_HAS_MEMBER_FUNCTION_HPP) 8 #define BOOST_TTI_HAS_MEMBER_FUNCTION_HPP 9 10 #include <boost/config.hpp> 11 #include <boost/function_types/property_tags.hpp> 12 #include <boost/mpl/vector.hpp> 13 #include <boost/preprocessor/cat.hpp> 14 #include <boost/tti/detail/ddeftype.hpp> 15 #include <boost/tti/detail/dmem_fun.hpp> 16 #include <boost/tti/gen/has_member_function_gen.hpp> 17 #include <boost/tti/gen/namespace_gen.hpp> 18 19 /* 20 21 The succeeding comments in this file are in doxygen format. 22 23 */ 24 25 /** \file 26 */ 27 28 /// A macro which expands to a metafunction which tests whether a member function with a particular name and signature exists. 29 /** 30 31 BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION is a macro which expands to a metafunction. 32 The metafunction tests whether a member function with a particular name 33 and signature exists. The macro takes the form of BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait,name) where 34 35 trait = the name of the metafunction <br/> 36 name = the name of the inner member. 37 38 BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION generates a metafunction called "trait" where 'trait' is the macro parameter. 39 40 @code 41 42 template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG> 43 struct trait 44 { 45 static const value = unspecified; 46 typedef mpl::bool_<true-or-false> type; 47 }; 48 49 The metafunction types and return: 50 51 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. 52 The enclosing type can be a class, struct, or union. 53 OR 54 a pointer to member function as a single type. 55 56 BOOST_TTI_TP_R = (optional) the return type of the member function 57 if the first parameter is the enclosing type. 58 59 BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence 60 if the first parameter is the enclosing type and the member function parameters 61 are not empty. 62 63 BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function 64 if the first parameter is the enclosing type and a tag is needed. 65 66 returns = 'value' is true if the 'name' exists, 67 with the appropriate member function type, 68 otherwise 'value' is false. 69 70 @endcode 71 72 */ 73 #define BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \ 74 BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \ 75 template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R = BOOST_TTI_NAMESPACE::detail::deftype,class BOOST_TTI_TP_FS = boost::mpl::vector<>,class BOOST_TTI_TP_TAG = boost::function_types::null_tag> \ 76 struct trait \ 77 { \ 78 typedef typename \ 79 BOOST_PP_CAT(trait,_detail_hmf)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \ 80 BOOST_STATIC_CONSTANT(bool,value=type::value); \ 81 }; \ 82 /**/ 83 84 /// A macro which expands to a metafunction which tests whether a member function with a particular name and signature exists. 85 /** 86 87 BOOST_TTI_HAS_MEMBER_FUNCTION is a macro which expands to a metafunction. 88 The metafunction tests whether a member function with a particular name 89 and signature exists. The macro takes the form of BOOST_TTI_HAS_MEMBER_FUNCTION(name) where 90 91 name = the name of the inner member. 92 93 BOOST_TTI_HAS_MEMBER_FUNCTION generates a metafunction called "has_member_function_name" where 'name' is the macro parameter. 94 95 @code 96 97 template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS,class BOOST_TTI_TP_TAG> 98 struct has_member_function_'name' 99 { 100 static const value = unspecified; 101 typedef mpl::bool_<true-or-false> type; 102 }; 103 104 The metafunction types and return: 105 106 BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'. 107 The enclosing type can be a class, struct, or union. 108 OR 109 a pointer to member function as a single type. 110 111 BOOST_TTI_TP_R = (optional) the return type of the member function 112 if the first parameter is the enclosing type. 113 114 BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence 115 if the first parameter is the enclosing type and the member function parameters 116 are not empty. 117 118 BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function 119 if the first parameter is the enclosing type and a tag is needed. 120 121 returns = 'value' is true if the 'name' exists, 122 with the appropriate member function type, 123 otherwise 'value' is false. 124 125 @endcode 126 127 */ 128 #define BOOST_TTI_HAS_MEMBER_FUNCTION(name) \ 129 BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION \ 130 ( \ 131 BOOST_TTI_HAS_MEMBER_FUNCTION_GEN(name), \ 132 name \ 133 ) \ 134 /**/ 135 136 #endif // BOOST_TTI_HAS_MEMBER_FUNCTION_HPP 137