File indexing completed on 2025-01-18 09:43:27
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_PARAMETER_AUX_PREPROCESSOR_IMPL_FUNCTION_CAST_HPP
0008 #define BOOST_PARAMETER_AUX_PREPROCESSOR_IMPL_FUNCTION_CAST_HPP
0009
0010 #include <boost/parameter/config.hpp>
0011
0012 #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
0013
0014 namespace boost { namespace parameter { namespace aux {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 template <typename VoidExpr, typename Args>
0032 struct cast;
0033 }}}
0034
0035 #include <boost/parameter/aux_/use_default_tag.hpp>
0036
0037 namespace boost { namespace parameter { namespace aux {
0038
0039 template <typename T, typename B>
0040 inline ::boost::parameter::aux::use_default_tag
0041 forward(::boost::parameter::aux::use_default_tag)
0042 {
0043 return ::boost::parameter::aux::use_default_tag();
0044 }
0045 }}}
0046
0047 #include <boost/mpl/bool.hpp>
0048 #include <boost/mpl/if.hpp>
0049
0050 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0051 #include <boost/mp11/integral.hpp>
0052 #include <boost/mp11/utility.hpp>
0053 #endif
0054
0055 namespace boost { namespace parameter { namespace aux {
0056
0057 template <typename Args>
0058 struct cast<void*,Args>
0059 {
0060 template <typename T, typename B>
0061 struct apply
0062 {
0063 typedef typename ::boost::mpl
0064 ::if_<B,T,::boost::mpl::true_>::type type;
0065 };
0066
0067 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0068 template <typename T, typename B>
0069 using fn = ::boost::mp11::mp_if<B,T,::boost::mp11::mp_true>;
0070 #endif
0071 };
0072 }}}
0073
0074 #include <boost/parameter/aux_/void.hpp>
0075
0076 namespace boost { namespace parameter { namespace aux {
0077
0078 template <typename Predicate, typename Args>
0079 struct cast<void*(Predicate),Args>
0080 : ::boost::parameter::aux::cast<void*,Args>
0081 {
0082 };
0083 }}}
0084
0085 #include <boost/mpl/placeholders.hpp>
0086
0087 namespace boost { namespace parameter { namespace aux {
0088
0089
0090
0091
0092 template <typename T, typename Dummy = ::boost::mpl::_1>
0093 struct as_placeholder_expr
0094 {
0095 typedef T type;
0096 };
0097 }}}
0098
0099 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0100 #include <boost/mp11/list.hpp>
0101
0102 namespace boost { namespace parameter { namespace aux {
0103
0104 template <typename Target, typename Source, typename Args>
0105 struct apply_target_fn
0106 {
0107 using type = ::boost::mp11
0108 ::mp_apply_q<Target,::boost::mp11::mp_list<Source,Args> >;
0109 };
0110 }}}
0111
0112 #endif
0113
0114 #include <boost/mpl/apply.hpp>
0115
0116 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0117 #include <boost/parameter/aux_/has_nested_template_fn.hpp>
0118 #include <type_traits>
0119 #else
0120 #include <boost/type_traits/is_same.hpp>
0121 #include <boost/type_traits/remove_const.hpp>
0122 #include <boost/type_traits/remove_reference.hpp>
0123 #endif
0124
0125 namespace boost { namespace parameter { namespace aux {
0126
0127 template <typename Target, typename Source, typename Args>
0128 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0129 using is_target_same_as_source = ::std::is_same<
0130 typename ::std::remove_const<
0131 typename ::std::remove_reference<
0132 typename ::boost::mp11::mp_if<
0133 ::boost::parameter::aux::has_nested_template_fn<Target>
0134 , ::boost::parameter::aux
0135 ::apply_target_fn<Target,Source,Args>
0136 , ::boost::mpl::apply2<
0137 ::boost::parameter::aux::as_placeholder_expr<Target>
0138 , Source
0139 , Args
0140 >
0141 >::type
0142 >::type
0143 >::type
0144 , typename ::std::remove_const<Source>::type
0145 >;
0146 #else
0147 struct is_target_same_as_source
0148 : ::boost::mpl::if_<
0149 ::boost::is_same<
0150 typename ::boost::remove_const<
0151 typename ::boost::remove_reference<
0152 typename ::boost::mpl::apply2<
0153 ::boost::parameter::aux
0154 ::as_placeholder_expr<Target>
0155 , Source
0156 , Args
0157 >::type
0158 >::type
0159 >::type
0160 , typename ::boost::remove_const<Source>::type
0161 >
0162 , ::boost::mpl::true_
0163 , ::boost::mpl::false_
0164 >::type
0165 {
0166 };
0167 #endif
0168 }}}
0169
0170 #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
0171 #include <boost/type_traits/add_const.hpp>
0172 #include <boost/type_traits/is_const.hpp>
0173 #endif
0174
0175 namespace boost { namespace parameter { namespace aux {
0176
0177
0178
0179
0180 template <typename Source, typename Target>
0181 class cast_convert
0182 {
0183 typedef ::boost::parameter::aux::cast_convert<Source,Target> _self;
0184
0185 public:
0186 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0187 using type = typename ::boost::mp11::mp_if<
0188 ::std::is_const<Source>
0189 , ::std::add_const<Target>
0190 , ::std::remove_const<Target>
0191 >::type;
0192 #else
0193 typedef typename boost::mpl::eval_if<
0194 ::boost::is_const<Source>
0195 , ::boost::add_const<Target>
0196 , ::boost::remove_const<Target>
0197 >::type type;
0198 #endif
0199
0200 private:
0201 inline static typename _self::type
0202 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0203 _copy(typename ::std::remove_const<Target>::type value)
0204 #else
0205 _copy(typename ::boost::remove_const<Target>::type value)
0206 #endif
0207 {
0208 return value;
0209 }
0210
0211 public:
0212 inline static typename _self::type evaluate(Source&& source)
0213 {
0214 return _self::_copy(source);
0215 }
0216 };
0217
0218 template <typename Target, typename Source, typename Args>
0219 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0220 using cast_impl = ::std::remove_reference<
0221 typename ::boost::mp11::mp_if<
0222 ::boost::parameter::aux::has_nested_template_fn<Target>
0223 , ::boost::parameter::aux
0224 ::is_target_same_as_source<Target,Source,Args>
0225 , ::boost::mpl::apply2<
0226 ::boost::parameter::aux::as_placeholder_expr<Target>
0227 , Source
0228 , Args
0229 >
0230 >::type
0231 >;
0232 #else
0233 struct cast_impl
0234 : ::boost::remove_reference<
0235 typename ::boost::mpl::apply2<
0236 ::boost::parameter::aux::as_placeholder_expr<Target>
0237 , Source
0238 , Args
0239 >::type
0240 >
0241 {
0242 };
0243 #endif
0244 }}}
0245
0246 #include <boost/mpl/eval_if.hpp>
0247 #include <boost/mpl/identity.hpp>
0248
0249 namespace boost { namespace parameter { namespace aux {
0250
0251 template <typename Target, typename Args>
0252 struct cast<void(Target),Args>
0253 {
0254 template <typename T, typename B>
0255 struct apply
0256 {
0257 typedef typename ::boost::mpl::eval_if<
0258 B
0259 , ::boost::mpl::eval_if<
0260 ::boost::parameter::aux
0261 ::is_target_same_as_source<Target,T,Args>
0262 , ::boost::mpl::identity<T>
0263 , ::boost::parameter::aux::cast_impl<Target,T,Args>
0264 >
0265 , ::boost::parameter::aux
0266 ::is_target_same_as_source<Target,T,Args>
0267 >::type type;
0268 };
0269
0270 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0271 template <typename T, typename B>
0272 using fn = typename ::boost::mp11::mp_if<
0273 B
0274 , ::boost::mp11::mp_if<
0275 ::boost::parameter::aux
0276 ::is_target_same_as_source<Target,T,Args>
0277 , ::boost::mp11::mp_identity<T>
0278 , ::boost::parameter::aux::cast_impl<Target,T,Args>
0279 >
0280 , ::boost::parameter::aux
0281 ::is_target_same_as_source<Target,T,Args>
0282 >::type;
0283 #endif
0284 };
0285 }}}
0286
0287 #include <boost/parameter/value_type.hpp>
0288
0289 #if !defined(BOOST_PARAMETER_CAN_USE_MP11)
0290 #include <boost/mpl/apply_wrap.hpp>
0291 #endif
0292
0293
0294 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0295 #define BOOST_PARAMETER_FUNCTION_CAST_T(tag, predicate, args) \
0296 ::boost::mp11::mp_apply_q< \
0297 ::boost::parameter::aux::cast<void predicate, args> \
0298 , ::boost::mp11::mp_list< \
0299 typename ::boost::parameter::value_type< \
0300 args \
0301 , tag \
0302 , ::boost::parameter::aux::use_default_tag \
0303 >::type \
0304 , ::boost::mp11::mp_true \
0305 > \
0306 >
0307
0308 #else
0309 #define BOOST_PARAMETER_FUNCTION_CAST_T(tag, predicate, args) \
0310 typename ::boost::mpl::apply_wrap2< \
0311 ::boost::parameter::aux::cast<void predicate, args> \
0312 , typename ::boost::parameter::value_type< \
0313 args \
0314 , tag \
0315 , ::boost::parameter::aux::use_default_tag \
0316 >::type \
0317 , ::boost::mpl::true_ \
0318 >::type
0319
0320 #endif
0321
0322
0323
0324 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0325 #define BOOST_PARAMETER_FUNCTION_CAST_B(tag, predicate, args) \
0326 ::boost::mp11::mp_apply_q< \
0327 ::boost::parameter::aux::cast<void predicate, args> \
0328 , ::boost::mp11::mp_list< \
0329 typename ::boost::parameter::value_type< \
0330 args \
0331 , tag \
0332 , ::boost::parameter::aux::use_default_tag \
0333 >::type \
0334 , ::boost::mp11::mp_false \
0335 > \
0336 >
0337
0338 #else
0339 #define BOOST_PARAMETER_FUNCTION_CAST_B(tag, predicate, args) \
0340 typename ::boost::mpl::apply_wrap2< \
0341 ::boost::parameter::aux::cast<void predicate, args> \
0342 , typename ::boost::parameter::value_type< \
0343 args \
0344 , tag \
0345 , ::boost::parameter::aux::use_default_tag \
0346 >::type \
0347 , ::boost::mpl::false_ \
0348 >::type
0349
0350 #endif
0351
0352 #include <boost/core/enable_if.hpp>
0353 #include <utility>
0354
0355 namespace boost { namespace parameter { namespace aux {
0356
0357
0358
0359 template <typename Target, typename B, typename Source>
0360 inline typename ::boost::lazy_disable_if<
0361 B
0362 , ::boost::parameter::aux::cast_convert<Source,Target>
0363 >::type
0364 forward(Source&& source)
0365 {
0366 return ::boost::parameter::aux::cast_convert<Source,Target>
0367 ::evaluate(::std::forward<Source>(source));
0368 }
0369
0370
0371
0372
0373 template <typename T, typename B>
0374 inline typename ::boost::enable_if<B,T const&>::type forward(T const& t)
0375 {
0376 return t;
0377 }
0378
0379 template <typename T, typename B>
0380 inline typename ::boost::enable_if<
0381 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0382 ::boost::mp11::mp_if<
0383 B
0384 , ::boost::mp11::mp_if<
0385 ::std::is_const<T>
0386 , ::boost::mp11::mp_false
0387 , ::boost::mp11::mp_true
0388 >
0389 , ::boost::mp11::mp_false
0390 >
0391 #else
0392 typename ::boost::mpl::eval_if<
0393 B
0394 , ::boost::mpl::if_<
0395 ::boost::is_const<T>
0396 , ::boost::mpl::false_
0397 , ::boost::mpl::true_
0398 >
0399 , ::boost::mpl::false_
0400 >::type
0401 #endif
0402 , T&
0403 >::type
0404 forward(T& t)
0405 {
0406 return t;
0407 }
0408 }}}
0409
0410 #include <boost/type_traits/is_scalar.hpp>
0411
0412 namespace boost { namespace parameter { namespace aux {
0413
0414 template <typename T, typename B>
0415 inline typename ::boost::enable_if<
0416 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0417 ::boost::mp11::mp_if<
0418 B
0419 , ::boost::mp11::mp_if<
0420 ::std::is_scalar<T>
0421 , ::boost::mp11::mp_false
0422 , ::boost::mp11::mp_true
0423 >
0424 , ::boost::mp11::mp_false
0425 >
0426 #else
0427 typename ::boost::mpl::eval_if<
0428 B
0429 , ::boost::mpl::if_<
0430 ::boost::is_scalar<T>
0431 , ::boost::mpl::false_
0432 , ::boost::mpl::true_
0433 >
0434 , ::boost::mpl::false_
0435 >::type
0436 #endif
0437 , T const&&
0438 >::type
0439 forward(T const&& t)
0440 {
0441 return static_cast<T const&&>(t);
0442 }
0443
0444 template <typename T, typename B>
0445 inline typename ::boost::enable_if<
0446 #if defined(BOOST_PARAMETER_CAN_USE_MP11)
0447 ::boost::mp11::mp_if<
0448 B
0449 , ::boost::mp11::mp_if<
0450 ::std::is_scalar<T>
0451 , ::boost::mp11::mp_false
0452 , ::boost::mp11::mp_true
0453 >
0454 , ::boost::mp11::mp_false
0455 >
0456 #else
0457 typename ::boost::mpl::eval_if<
0458 B
0459 , ::boost::mpl::if_<
0460 ::boost::is_scalar<T>
0461 , ::boost::mpl::false_
0462 , ::boost::mpl::true_
0463 >
0464 , ::boost::mpl::false_
0465 >::type
0466 #endif
0467 , T&&
0468 >::type
0469 forward(T&& t)
0470 {
0471 return ::std::forward<T>(t);
0472 }
0473 }}}
0474
0475 #elif BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0476 #define BOOST_PARAMETER_FUNCTION_CAST_T(value_t, predicate, args) value_t
0477 #define BOOST_PARAMETER_FUNCTION_CAST_B(value, predicate, args) value
0478 #else
0479
0480 namespace boost { namespace parameter { namespace aux {
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497 template <typename VoidExpr, typename Args>
0498 struct cast;
0499 }}}
0500
0501 #include <boost/parameter/aux_/use_default_tag.hpp>
0502 #include <boost/mpl/bool.hpp>
0503 #include <boost/mpl/if.hpp>
0504
0505 namespace boost { namespace parameter { namespace aux {
0506
0507 template <typename Args>
0508 struct cast<void*,Args>
0509 {
0510 template <typename T>
0511 struct apply
0512 {
0513 typedef T& type;
0514 };
0515
0516 inline static ::boost::parameter::aux::use_default_tag
0517 execute(::boost::parameter::aux::use_default_tag)
0518 {
0519 return ::boost::parameter::aux::use_default_tag();
0520 }
0521
0522 template <typename U>
0523 inline static U& execute(U& value)
0524 {
0525 return value;
0526 }
0527 };
0528 }}}
0529
0530 #include <boost/parameter/aux_/void.hpp>
0531
0532 namespace boost { namespace parameter { namespace aux {
0533
0534 template <typename Predicate, typename Args>
0535 #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
0536 struct cast< ::boost::parameter::aux::voidstar(Predicate),Args>
0537 #else
0538 struct cast<void*(Predicate),Args>
0539 #endif
0540 : ::boost::parameter::aux::cast<void*,Args>
0541 {
0542 };
0543 }}}
0544
0545 #include <boost/mpl/placeholders.hpp>
0546
0547 namespace boost { namespace parameter { namespace aux {
0548
0549
0550
0551
0552 template <typename T, typename Dummy = ::boost::mpl::_1>
0553 struct as_placeholder_expr
0554 {
0555 typedef T type;
0556 };
0557 }}}
0558
0559 #include <boost/mpl/apply.hpp>
0560 #include <boost/type_traits/is_same.hpp>
0561 #include <boost/type_traits/remove_const.hpp>
0562 #include <boost/type_traits/remove_reference.hpp>
0563
0564 namespace boost { namespace parameter { namespace aux {
0565
0566 template <typename Target, typename Source, typename Args>
0567 struct is_target_same_as_source
0568 : ::boost::mpl::if_<
0569 ::boost::is_same<
0570 typename ::boost::remove_const<
0571 typename ::boost::remove_reference<
0572 typename ::boost::mpl::apply2<
0573 ::boost::parameter::aux
0574 ::as_placeholder_expr<Target>
0575 , Source
0576 , Args
0577 >::type
0578 >::type
0579 >::type
0580 , typename ::boost::remove_const<Source>::type
0581 >
0582 , ::boost::mpl::true_
0583 , ::boost::mpl::false_
0584 >::type
0585 {
0586 };
0587
0588 template <
0589 typename Target
0590 , typename Source
0591 , typename Args
0592 , typename Enable = ::boost::parameter::aux
0593 ::is_target_same_as_source<Target,Source,Args>
0594 >
0595 struct cast_impl
0596 {
0597 typedef Source& type;
0598
0599 inline static Source& evaluate(Source& value)
0600 {
0601 return value;
0602 }
0603 };
0604 }}}
0605
0606 #include <boost/type_traits/add_const.hpp>
0607 #include <boost/type_traits/add_lvalue_reference.hpp>
0608
0609 namespace boost { namespace parameter { namespace aux {
0610
0611
0612
0613
0614 template <typename Source, typename Target>
0615 class cast_convert
0616 {
0617 typedef ::boost::parameter::aux::cast_convert<Source,Target> _self;
0618
0619 public:
0620 typedef typename ::boost::add_lvalue_reference<
0621 typename ::boost::add_const<Target>::type
0622 >::type type;
0623
0624 private:
0625 template <typename U>
0626 inline static typename _self::type _mod_const(U const& u)
0627 {
0628 return u;
0629 }
0630
0631 inline static Target _copy(Target value)
0632 {
0633 return value;
0634 }
0635
0636 public:
0637 inline static typename _self::type evaluate(Source& source)
0638 {
0639 return _self::_mod_const(_self::_copy(source));
0640 }
0641 };
0642
0643 template <typename Target, typename Source, typename Args>
0644 struct cast_impl<Target,Source,Args,::boost::mpl::false_>
0645 : ::boost::parameter::aux::cast_convert<
0646 Source,
0647 typename ::boost::mpl::apply2<
0648 ::boost::parameter::aux::as_placeholder_expr<Target>
0649 , Source
0650 , Args
0651 >::type
0652 >
0653 {
0654 };
0655 }}}
0656
0657 #include <boost/mpl/eval_if.hpp>
0658
0659 namespace boost { namespace parameter { namespace aux {
0660
0661 template <typename Target, typename Args>
0662 struct cast<void(Target),Args>
0663 {
0664 template <typename T>
0665 struct apply
0666 {
0667 typedef typename ::boost::mpl::eval_if<
0668 ::boost::parameter::aux
0669 ::is_target_same_as_source<Target,T,Args>
0670 , ::boost::add_lvalue_reference<T>
0671 , ::boost::parameter::aux::cast_impl<
0672 Target
0673 , T
0674 , Args
0675 , ::boost::mpl::false_
0676 >
0677 >::type type;
0678 };
0679
0680 inline static ::boost::parameter::aux::use_default_tag
0681 execute(::boost::parameter::aux::use_default_tag)
0682 {
0683 return ::boost::parameter::aux::use_default_tag();
0684 }
0685
0686 template <typename U>
0687 inline static typename ::boost::parameter::aux
0688 ::cast_impl<Target,U const,Args>::type
0689 execute(U const& value)
0690 {
0691 return ::boost::parameter::aux
0692 ::cast_impl<Target,U const,Args>::evaluate(value);
0693 }
0694
0695 template <typename U>
0696 inline static typename ::boost::parameter::aux
0697 ::cast_impl<Target,U,Args>::type
0698 execute(U& value)
0699 {
0700 return ::boost::parameter::aux
0701 ::cast_impl<Target,U,Args>::evaluate(value);
0702 }
0703 };
0704 }}}
0705
0706 #include <boost/mpl/apply_wrap.hpp>
0707 #include <boost/parameter/value_type.hpp>
0708
0709
0710
0711 #define BOOST_PARAMETER_FUNCTION_CAST_T(tag, predicate, args) \
0712 typename ::boost::mpl::apply_wrap1< \
0713 ::boost::parameter::aux::cast<void predicate, args> \
0714 , typename ::boost::parameter::value_type< \
0715 args \
0716 , tag \
0717 , ::boost::parameter::aux::use_default_tag \
0718 >::type \
0719 >::type
0720
0721
0722
0723
0724 #define BOOST_PARAMETER_FUNCTION_CAST_B(value, predicate, args) \
0725 ::boost::parameter::aux::cast<void predicate, args>::execute(value)
0726
0727
0728 #endif
0729 #endif
0730