1 // Copyright Cromwell D. Enage 2017. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 #ifndef LIBS_PARAMETER_TEST_EVALUTE_CATEGORY_HPP 7 #define LIBS_PARAMETER_TEST_EVALUTE_CATEGORY_HPP 8 9 namespace test { 10 11 enum invoked 12 { 13 passed_by_lvalue_reference_to_const 14 , passed_by_lvalue_reference 15 , passed_by_rvalue_reference_to_const 16 , passed_by_rvalue_reference 17 }; 18 rvalue_float()19 float rvalue_float() 20 { 21 return 0.0f; 22 } 23 rvalue_const_float()24 float const rvalue_const_float() 25 { 26 return 0.0f; 27 } 28 lvalue_float()29 float& lvalue_float() 30 { 31 static float lfloat = 0.0f; 32 return lfloat; 33 } 34 lvalue_const_float()35 float const& lvalue_const_float() 36 { 37 static float const clfloat = 0.0f; 38 return clfloat; 39 } 40 rvalue_char_ptr()41 char const* rvalue_char_ptr() 42 { 43 return "foo"; 44 } 45 rvalue_const_char_ptr()46 char const* const rvalue_const_char_ptr() 47 { 48 return "foo"; 49 } 50 lvalue_char_ptr()51 char const*& lvalue_char_ptr() 52 { 53 static char const* larr = "foo"; 54 return larr; 55 } 56 lvalue_const_char_ptr()57 char const* const& lvalue_const_char_ptr() 58 { 59 static char const* const clarr = "foo"; 60 return clarr; 61 } 62 } // namespace test 63 64 #include <string> 65 66 namespace test { 67 rvalue_str()68 std::string rvalue_str() 69 { 70 return std::string("bar"); 71 } 72 rvalue_const_str()73 std::string const rvalue_const_str() 74 { 75 return std::string("bar"); 76 } 77 lvalue_str()78 std::string& lvalue_str() 79 { 80 static std::string lstr = std::string("bar"); 81 return lstr; 82 } 83 lvalue_const_str()84 std::string const& lvalue_const_str() 85 { 86 static std::string const clstr = std::string("bar"); 87 return clstr; 88 } 89 } // namespace test 90 91 #include <bitset> 92 93 namespace test { 94 95 template <std::size_t N> rvalue_bitset()96 std::bitset<N + 1> rvalue_bitset() 97 { 98 return std::bitset<N + 1>(); 99 } 100 101 template <std::size_t N> rvalue_const_bitset()102 std::bitset<N + 1> const rvalue_const_bitset() 103 { 104 return std::bitset<N + 1>(); 105 } 106 107 template <std::size_t N> lvalue_bitset()108 std::bitset<N + 1>& lvalue_bitset() 109 { 110 static std::bitset<N + 1> lset = std::bitset<N + 1>(); 111 return lset; 112 } 113 114 template <std::size_t N> lvalue_const_bitset()115 std::bitset<N + 1> const& lvalue_const_bitset() 116 { 117 static std::bitset<N + 1> const clset = std::bitset<N + 1>(); 118 return clset; 119 } 120 121 template <std::size_t N> 122 struct lvalue_bitset_function 123 { 124 typedef std::bitset<N + 1>& result_type; 125 operator ()test::lvalue_bitset_function126 result_type operator()() const 127 { 128 return test::lvalue_bitset<N>(); 129 } 130 }; 131 132 template <std::size_t N> 133 struct lvalue_const_bitset_function 134 { 135 typedef std::bitset<N + 1> const& result_type; 136 operator ()test::lvalue_const_bitset_function137 result_type operator()() const 138 { 139 return test::lvalue_const_bitset<N>(); 140 } 141 }; 142 143 template <std::size_t N> 144 struct rvalue_bitset_function 145 { 146 typedef std::bitset<N + 1> result_type; 147 operator ()test::rvalue_bitset_function148 result_type operator()() const 149 { 150 return test::rvalue_bitset<N>(); 151 } 152 }; 153 154 template <std::size_t N> 155 struct rvalue_const_bitset_function 156 { 157 typedef std::bitset<N + 1> const result_type; 158 operator ()test::rvalue_const_bitset_function159 result_type operator()() const 160 { 161 return test::rvalue_const_bitset<N>(); 162 } 163 }; 164 } // namespace test 165 166 #include <boost/parameter/config.hpp> 167 168 namespace test { 169 170 template <typename T> 171 struct A 172 { evaluate_categorytest::A173 static test::invoked evaluate_category(T const&) 174 { 175 return test::passed_by_lvalue_reference_to_const; 176 } 177 evaluate_categorytest::A178 static test::invoked evaluate_category(T&) 179 { 180 return test::passed_by_lvalue_reference; 181 } 182 183 #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) evaluate_categorytest::A184 static test::invoked evaluate_category(T const&&) 185 { 186 return test::passed_by_rvalue_reference_to_const; 187 } 188 evaluate_categorytest::A189 static test::invoked evaluate_category(T&&) 190 { 191 return test::passed_by_rvalue_reference; 192 } 193 #endif 194 }; 195 196 struct U 197 { 198 template <std::size_t N> evaluate_categorytest::U199 static test::invoked evaluate_category(std::bitset<N + 1> const&) 200 { 201 return test::passed_by_lvalue_reference_to_const; 202 } 203 204 template <std::size_t N> evaluate_categorytest::U205 static test::invoked evaluate_category(std::bitset<N + 1>&) 206 { 207 return test::passed_by_lvalue_reference; 208 } 209 210 #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) 211 template <std::size_t N> evaluate_categorytest::U212 static test::invoked evaluate_category(std::bitset<N + 1> const&&) 213 { 214 return test::passed_by_rvalue_reference_to_const; 215 } 216 217 template <std::size_t N> evaluate_categorytest::U218 static test::invoked evaluate_category(std::bitset<N + 1>&&) 219 { 220 return test::passed_by_rvalue_reference; 221 } 222 #endif 223 }; 224 } // namespace test 225 226 #include <boost/parameter/value_type.hpp> 227 228 #if defined(BOOST_PARAMETER_CAN_USE_MP11) 229 #include <type_traits> 230 #else 231 #include <boost/mpl/bool.hpp> 232 #include <boost/mpl/if.hpp> 233 #include <boost/type_traits/is_convertible.hpp> 234 #include <boost/type_traits/remove_const.hpp> 235 #include <boost/type_traits/remove_pointer.hpp> 236 #endif 237 238 namespace test { 239 240 template <typename CharConstPtrParamTag> 241 struct string_predicate 242 { 243 template <typename Arg, typename Args> 244 #if defined(BOOST_PARAMETER_CAN_USE_MP11) 245 using fn = std::is_convertible< 246 Arg 247 , std::basic_string< 248 typename std::remove_const< 249 typename std::remove_pointer< 250 typename boost::parameter::value_type< 251 Args 252 , CharConstPtrParamTag 253 #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE) 254 , char const* 255 #endif 256 >::type 257 >::type 258 >::type 259 > 260 >; 261 #else // !defined(BOOST_PARAMETER_CAN_USE_MP11) 262 struct apply 263 : boost::mpl::if_< 264 boost::is_convertible< 265 Arg 266 , std::basic_string< 267 typename boost::remove_const< 268 typename boost::remove_pointer< 269 typename boost::parameter::value_type< 270 Args 271 , CharConstPtrParamTag 272 #if !defined(LIBS_PARAMETER_TEST_COMPILE_FAILURE) 273 , char const* 274 #endif 275 >::type 276 >::type 277 >::type 278 > 279 > 280 , boost::mpl::true_ 281 , boost::mpl::false_ 282 > 283 { 284 }; 285 #endif // BOOST_PARAMETER_CAN_USE_MP11 286 }; 287 } // namespace test 288 289 #endif // include guard 290 291