Ticket #2793: arg_list.diff
File arg_list.diff, 4.4 KB (added by , 10 years ago) |
---|
-
boost/parameter/aux_/arg_list.hpp
25 25 #include <boost/preprocessor/repetition/enum_params.hpp> 26 26 #include <boost/preprocessor/repetition/enum_binary_params.hpp> 27 27 #include <boost/preprocessor/facilities/intercept.hpp> 28 #include <boost/utility/enable_if.hpp> 28 29 29 30 namespace boost { namespace parameter { 30 31 … … 187 188 , typename TaggedArg::value_type 188 189 >::type value_type; 189 190 191 private: 192 // This metafunction is used to make a type dependent on a template 193 // parameter. This is required below to delay the instantiation of the 194 // return type of functions. 195 // Since `arg_list` is used for named template parameters, the `reference` 196 // type can't always be expected to be a type valid as a return type 197 // (it could legitimately be a function type or an array type). Unless 198 // delayed, the function signatures are instantiated even when the 199 // functions are not actually used (in the case of named template 200 // parameters) because of how the `arg_list` is implemented; by means 201 // of inheritance from `Next`. 202 // 203 // Note: In the code below, we sometimes use enable_if with is_same 204 // when the signature is not really dependent on anything but 205 // we still need to introduce a template parameter to have a 206 // dependent return type. 207 template <class Dummy, class Type> 208 struct make_dependent_on { 209 typedef Type type; 210 }; 211 212 public: 213 190 214 TaggedArg arg; // Stores the argument 191 215 192 216 // Store the arguments in successive nodes of this list … … 255 279 // Helpers that handle the case when TaggedArg is 256 280 // empty<T>. 257 281 template <class D> 258 reference get_default(D const&, mpl::false_) const 282 typename make_dependent_on<D, reference>::type 283 get_default(D const&, mpl::false_) const 259 284 { 260 285 return arg.value; 261 286 } 262 287 263 288 template <class D> 264 reference get_default(D const& d, mpl::true_) const 289 typename make_dependent_on<D, reference>::type 290 get_default(D const& d, mpl::true_) const 265 291 { 266 292 return arg.value ? arg.value.get() : arg.value.construct(d.value); 267 293 } … … 323 349 // reached, indicating no matching argument was passed, the 324 350 // default is returned, or if no default_ or lazy_default was 325 351 // passed, compilation fails. 326 reference get(keyword<key_type> const&) const 352 353 // Note: See the comment @make_dependent_on to know the rationale behind 354 // the use of enable_if with is_same instead of a straight overload. 355 template <class KeyType> 356 typename enable_if<is_same<KeyType, key_type>, 357 reference>::type get(keyword<KeyType> const&) const 327 358 { 328 359 BOOST_MPL_ASSERT_NOT((holds_maybe)); 329 360 return arg.value; 330 361 } 331 362 332 363 template <class Default> 333 reference get(default_<key_type,Default> const& d) const 364 typename make_dependent_on<Default, reference>::type 365 get(default_<key_type,Default> const& d) const 334 366 { 335 367 return get_default(d, holds_maybe()); 336 368 } 337 369 338 370 template <class Default> 339 reference get(lazy_default<key_type, Default>) const 371 typename make_dependent_on<Default, reference>::type 372 get(lazy_default<key_type, Default>) const 340 373 { 341 374 return arg.value; 342 375 } 343 376 344 377 #else 345 378 346 reference operator[](keyword<key_type> const&) const 379 // Note: See the comment @make_dependent_on to know the rationale behind 380 // the use of enable_if with is_same instead of a straight overload. 381 template <class KeyType> 382 typename enable_if<is_same<KeyType, key_type>, 383 reference>::type operator[](keyword<KeyType> const&) const 347 384 { 348 385 BOOST_MPL_ASSERT_NOT((holds_maybe)); 349 386 return arg.value; 350 387 } 351 388 352 389 template <class Default> 353 reference operator[](default_<key_type, Default> const& d) const 390 typename make_dependent_on<Default, reference>::type 391 operator[](default_<key_type, Default> const& d) const 354 392 { 355 393 return get_default(d, holds_maybe()); 356 394 } 357 395 358 396 template <class Default> 359 reference operator[](lazy_default<key_type, Default>) const 397 typename make_dependent_on<Default, reference>::type 398 operator[](lazy_default<key_type, Default>) const 360 399 { 361 400 return arg.value; 362 401 }