File indexing completed on 2025-12-16 10:10:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #if !defined(BOOST_PP_IS_ITERATING)
0012
0013 #ifndef BOOST_TYPE_ERASURE_TUPLE_HPP_INCLUDED
0014 #define BOOST_TYPE_ERASURE_TUPLE_HPP_INCLUDED
0015
0016 #include <boost/config.hpp>
0017
0018
0019 #ifdef BOOST_TYPE_ERASURE_DOXYGEN
0020
0021 namespace boost {
0022 namespace type_erasure {
0023
0024
0025
0026
0027
0028
0029
0030
0031 template<class Concept, class... T>
0032 class tuple
0033 {
0034 public:
0035
0036
0037
0038
0039
0040
0041
0042 template<class... U>
0043 explicit tuple(U&&... args);
0044 };
0045
0046
0047
0048
0049 template<int N, class Concept, class... T>
0050 any<Concept, TN>& get(tuple<Concept, T...>& arg);
0051
0052 template<int N, class Concept, class... T>
0053 const any<Concept, TN>& get(const tuple<Concept, T...>& arg);
0054
0055 }
0056 }
0057
0058 #elif !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0059
0060 #include <boost/mpl/int.hpp>
0061 #include <boost/mpl/bool.hpp>
0062 #include <boost/mpl/map.hpp>
0063 #include <boost/mpl/insert.hpp>
0064 #include <boost/type_traits/remove_reference.hpp>
0065 #include <boost/type_traits/remove_const.hpp>
0066 #include <boost/fusion/include/category_of.hpp>
0067 #include <boost/fusion/include/iterator_facade.hpp>
0068 #include <boost/fusion/include/sequence_facade.hpp>
0069 #include <boost/type_erasure/any.hpp>
0070 #include <boost/type_erasure/static_binding.hpp>
0071 #include <boost/type_erasure/config.hpp>
0072
0073 namespace boost {
0074 namespace type_erasure {
0075
0076 template<class Concept, class... T>
0077 struct cons;
0078
0079 template<class Concept>
0080 struct cons<Concept>
0081 {
0082 template<class Binding>
0083 cons(const Binding&) {}
0084 };
0085
0086 template<class Concept, class T0, class... T>
0087 struct cons<Concept, T0, T...>
0088 {
0089 typedef any<Concept, T0> value_type;
0090 typedef cons<Concept, T...> rest_type;
0091 template<class Binding, class U0, class... U>
0092 cons(const Binding& b, U0&& u0, U&&... u)
0093 : value(std::forward<U0>(u0), b),
0094 rest(b, std::forward<U>(u)...)
0095 {}
0096 any<Concept, T0> value;
0097 cons<Concept, T...> rest;
0098 };
0099
0100 namespace detail {
0101
0102 template<int N, class Cons>
0103 struct cons_advance
0104 {
0105 typedef typename cons_advance<N-1, Cons>::type::rest_type type;
0106 static const type& call(const Cons& c)
0107 {
0108 return cons_advance<N-1, Cons>::call(c).rest;
0109 }
0110 };
0111
0112 template<class Cons>
0113 struct cons_advance<0, Cons>
0114 {
0115 typedef Cons type;
0116 static const type& call(const Cons& c)
0117 {
0118 return c;
0119 }
0120 };
0121
0122 template<class... T>
0123 struct make_map;
0124
0125 template<class T0, class... T>
0126 struct make_map<T0, T...>
0127 {
0128 typedef typename ::boost::mpl::insert<
0129 typename ::boost::type_erasure::detail::make_map<T...>::type,
0130 T0
0131 >::type type;
0132 };
0133
0134 template<>
0135 struct make_map<>
0136 {
0137 typedef ::boost::mpl::map0<> type;
0138 };
0139
0140 }
0141
0142
0143 template<class Tuple, int N>
0144 class tuple_iterator :
0145 public ::boost::fusion::iterator_facade<
0146 tuple_iterator<Tuple, N>,
0147 ::boost::fusion::random_access_traversal_tag
0148 >
0149 {
0150 public:
0151 typedef ::boost::mpl::int_<N> index;
0152 explicit tuple_iterator(Tuple& t_arg) : t(&t_arg) {}
0153 template<class It>
0154 struct value_of
0155 {
0156 typedef typename Tuple::template value_at<Tuple, mpl::int_<N> >::type type;
0157 };
0158 template<class It>
0159 struct deref
0160 {
0161 typedef typename Tuple::template at<Tuple, mpl::int_<N> >::type type;
0162 static type call(It it)
0163 {
0164 return Tuple::template at<Tuple, mpl::int_<N> >::call(*it.t);
0165 }
0166 };
0167 template<class It, class M>
0168 struct advance
0169 {
0170 typedef tuple_iterator<Tuple, (It::index::value+M::value)> type;
0171 static type call(It it) { return type(*it.t); }
0172 };
0173 template<class It>
0174 struct next : advance<It, ::boost::mpl::int_<1> > {};
0175 template<class It>
0176 struct prior : advance<It, ::boost::mpl::int_<-1> > {};
0177 template<class It1, class It2>
0178 struct distance
0179 {
0180 typedef typename ::boost::mpl::minus<
0181 typename It2::index,
0182 typename It1::index
0183 >::type type;
0184 static type call(It1, It2) { return type(); }
0185 };
0186 private:
0187 Tuple* t;
0188 };
0189
0190 template<class Concept, class... T>
0191 class tuple :
0192 public ::boost::fusion::sequence_facade<
0193 ::boost::type_erasure::tuple<Concept, T...>,
0194 ::boost::fusion::forward_traversal_tag
0195 >
0196 {
0197 public:
0198 template<class... U>
0199 explicit tuple(U&&... args)
0200 : impl(
0201 ::boost::type_erasure::make_binding<
0202 typename ::boost::type_erasure::detail::make_map<
0203 ::boost::mpl::pair<
0204 typename ::boost::remove_const<
0205 typename ::boost::remove_reference<T>::type
0206 >::type,
0207 typename ::boost::remove_const<
0208 typename ::boost::remove_reference<U>::type
0209 >::type
0210 >...
0211 >::type
0212 >(),
0213 std::forward<U>(args)...)
0214 {}
0215
0216 template<class Seq>
0217 struct begin
0218 {
0219 typedef ::boost::type_erasure::tuple_iterator<
0220 Seq,
0221 0
0222 > type;
0223 static type call(Seq& seq) { return type(seq); }
0224 };
0225 template<class Seq>
0226 struct end
0227 {
0228 typedef ::boost::type_erasure::tuple_iterator<
0229 Seq,
0230 sizeof...(T)
0231 > type;
0232 static type call(Seq& seq) { return type(seq); }
0233 };
0234 template<class Seq>
0235 struct size
0236 {
0237 typedef ::boost::mpl::int_<sizeof...(T)> type;
0238 static type call(Seq& seq) { return type(); }
0239 };
0240 template<class Seq>
0241 struct empty
0242 {
0243 typedef ::boost::mpl::bool_<sizeof...(T) == 0> type;
0244 static type call(Seq& seq) { return type(); }
0245 };
0246 template<class Seq, class N>
0247 struct at
0248 {
0249 typedef typename ::boost::type_erasure::detail::cons_advance<
0250 N::value,
0251 ::boost::type_erasure::cons<Concept, T...>
0252 >::type::value_type value_type;
0253 typedef typename ::boost::mpl::if_< ::boost::is_const<Seq>,
0254 const value_type&,
0255 value_type&
0256 >::type type;
0257 static type call(Seq& seq)
0258 {
0259 return const_cast<type>(
0260 ::boost::type_erasure::detail::cons_advance<
0261 N::value,
0262 ::boost::type_erasure::cons<Concept, T...>
0263 >::call(seq.impl).value
0264 );
0265 }
0266 };
0267 template<class Seq, class N>
0268 struct value_at
0269 {
0270 typedef typename ::boost::type_erasure::detail::cons_advance<
0271 N::value,
0272 ::boost::type_erasure::cons<Concept, T...>
0273 >::type::value_type value_type;
0274 };
0275 ::boost::type_erasure::cons<Concept, T...> impl;
0276 };
0277
0278 template<int N, class Concept, class... T>
0279 typename ::boost::type_erasure::detail::cons_advance<
0280 N,
0281 ::boost::type_erasure::cons<Concept, T...>
0282 >::type::value_type& get(::boost::type_erasure::tuple<Concept, T...>& t)
0283 {
0284 return const_cast<
0285 typename ::boost::type_erasure::detail::cons_advance<
0286 N,
0287 ::boost::type_erasure::cons<Concept, T...>
0288 >::type::value_type&
0289 >(
0290 ::boost::type_erasure::detail::cons_advance<N,
0291 ::boost::type_erasure::cons<Concept, T...>
0292 >::call(t.impl).value
0293 );
0294 }
0295
0296 template<int N, class Concept, class... T>
0297 const typename ::boost::type_erasure::detail::cons_advance<
0298 N,
0299 ::boost::type_erasure::cons<Concept, T...>
0300 >::type::value_type& get(const ::boost::type_erasure::tuple<Concept, T...>& t)
0301 {
0302 return ::boost::type_erasure::detail::cons_advance<
0303 N,
0304 ::boost::type_erasure::cons<Concept, T...>
0305 >::call(t.impl).value;
0306 }
0307
0308 }
0309 }
0310
0311 #else
0312
0313 #include <boost/mpl/int.hpp>
0314 #include <boost/mpl/minus.hpp>
0315 #include <boost/mpl/equal_to.hpp>
0316 #include <boost/mpl/map.hpp>
0317 #include <boost/fusion/include/category_of.hpp>
0318 #include <boost/fusion/include/iterator_facade.hpp>
0319 #include <boost/fusion/include/sequence_facade.hpp>
0320 #include <boost/preprocessor/cat.hpp>
0321 #include <boost/preprocessor/iteration/iterate.hpp>
0322 #include <boost/preprocessor/repetition/repeat.hpp>
0323 #include <boost/preprocessor/repetition/enum.hpp>
0324 #include <boost/preprocessor/repetition/enum_params.hpp>
0325 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
0326 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0327 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
0328 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
0329 #include <boost/type_erasure/any.hpp>
0330 #include <boost/type_erasure/static_binding.hpp>
0331 #include <boost/type_erasure/config.hpp>
0332
0333 namespace boost {
0334 namespace type_erasure {
0335
0336
0337 struct na {};
0338
0339 namespace detail {
0340
0341 template<int N, class Tuple>
0342 struct get_impl;
0343
0344 template<class Concept,
0345 BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
0346 BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, class T, ::boost::type_erasure::na)>
0347 struct tuple_storage;
0348
0349 }
0350
0351
0352 template<class Tuple, int N>
0353 class tuple_iterator :
0354 public ::boost::fusion::iterator_facade<
0355 tuple_iterator<Tuple, N>,
0356 ::boost::fusion::random_access_traversal_tag
0357 >
0358 {
0359 public:
0360 typedef ::boost::mpl::int_<N> index;
0361 explicit tuple_iterator(Tuple& t_arg) : t(&t_arg) {}
0362 template<class It>
0363 struct value_of
0364 {
0365 typedef typename ::boost::type_erasure::detail::get_impl<
0366 It::index::value,
0367 Tuple
0368 >::value_type type;
0369 };
0370 template<class It>
0371 struct deref :
0372 ::boost::type_erasure::detail::get_impl<It::index::value, Tuple>
0373 {
0374 typedef typename ::boost::type_erasure::detail::get_impl<
0375 It::index::value,
0376 Tuple
0377 >::type type;
0378 static type call(It it)
0379 {
0380 return ::boost::type_erasure::detail::get_impl<
0381 It::index::value,
0382 Tuple
0383 >::call(*it.t);
0384 }
0385 };
0386 template<class It, class M>
0387 struct advance
0388 {
0389 typedef tuple_iterator<Tuple, (It::index::value+M::value)> type;
0390 static type call(It it) { return type(*it.t); }
0391 };
0392 template<class It>
0393 struct next : advance<It, ::boost::mpl::int_<1> > {};
0394 template<class It>
0395 struct prior : advance<It, ::boost::mpl::int_<-1> > {};
0396 template<class It1, class It2>
0397 struct distance
0398 {
0399 typedef typename ::boost::mpl::minus<
0400 typename It2::index,
0401 typename It1::index
0402 >::type type;
0403 static type call(It1, It2) { return type(); }
0404 };
0405 private:
0406 Tuple* t;
0407 };
0408
0409
0410 template<class Derived>
0411 struct tuple_base :
0412 ::boost::fusion::sequence_facade<
0413 Derived,
0414 ::boost::fusion::random_access_traversal_tag
0415 >
0416 {
0417 template<class Seq>
0418 struct begin
0419 {
0420 typedef ::boost::type_erasure::tuple_iterator<Seq, 0> type;
0421 static type call(Seq& seq) { return type(seq); }
0422 };
0423 template<class Seq>
0424 struct end
0425 {
0426 typedef ::boost::type_erasure::tuple_iterator<
0427 Seq,
0428 Seq::tuple_size::value
0429 > type;
0430 static type call(Seq& seq) { return type(seq); }
0431 };
0432 template<class Seq>
0433 struct size
0434 {
0435 typedef typename Seq::tuple_size type;
0436 static type call(Seq& seq) { return type(); }
0437 };
0438 template<class Seq>
0439 struct empty
0440 {
0441 typedef typename boost::mpl::equal_to<
0442 typename Seq::tuple_size,
0443 boost::mpl::int_<0>
0444 >::type type;
0445 static type call(Seq& seq) { return type(); }
0446 };
0447 template<class Seq, class N>
0448 struct at : ::boost::type_erasure::detail::get_impl<N::value, Seq> {};
0449 template<class Seq, class N>
0450 struct value_at
0451 {
0452 typedef typename ::boost::type_erasure::detail::get_impl<
0453 N::value,
0454 Seq
0455 >::value_type type;
0456 };
0457 };
0458
0459 template<class Concept,
0460 BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
0461 BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, class T, ::boost::type_erasure::na)>
0462 class tuple;
0463
0464 template<
0465 int N,
0466 class Concept
0467 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, class T)
0468 >
0469 typename detail::get_impl<
0470 N,
0471 tuple<
0472 Concept
0473 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0474 >
0475 >::type get(
0476 tuple<
0477 Concept
0478 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0479 >& arg)
0480 {
0481 return detail::get_impl<
0482 N,
0483 tuple<
0484 Concept
0485 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0486 >
0487 >::call(arg);
0488 }
0489
0490 template<
0491 int N,
0492 class Concept
0493 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, class T)
0494 >
0495 typename detail::get_impl<
0496 N,
0497 const tuple<
0498 Concept
0499 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0500 >
0501 >::type get(
0502 const tuple<
0503 Concept
0504 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0505 >& arg)
0506 {
0507 return detail::get_impl<
0508 N,
0509 const tuple<
0510 Concept
0511 BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE, T)
0512 >
0513 >::call(arg);
0514 }
0515
0516
0517 #define BOOST_PP_FILENAME_1 <boost/type_erasure/tuple.hpp>
0518
0519 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE)
0520 #include BOOST_PP_ITERATE()
0521
0522 }
0523 }
0524
0525 #endif
0526
0527 #endif
0528
0529 #else
0530
0531 #define N BOOST_PP_ITERATION()
0532
0533 #define BOOST_TYPE_ERASURE_TAG_TYPEDEF(z, n, data) \
0534 typedef BOOST_PP_CAT(T, n) BOOST_PP_CAT(tag_type, n); \
0535 typedef typename ::boost::remove_reference<BOOST_PP_CAT(T, n)>::type \
0536 BOOST_PP_CAT(tag, n);
0537
0538 #define BOOST_TYPE_ERASURE_PAIR(z, n, data) \
0539 ::boost::mpl::pair<BOOST_PP_CAT(tag, n), BOOST_PP_CAT(U, n)>
0540
0541 #define BOOST_TYPE_ERASURE_CONSTRUCT(z, n, data)\
0542 BOOST_PP_CAT(t, n)(BOOST_PP_CAT(u, n), table)
0543
0544 #define BOOST_TYPE_ERASURE_TUPLE_MEMBER(z, n, data)\
0545 ::boost::type_erasure::any<Concept, BOOST_PP_CAT(T, n)> BOOST_PP_CAT(t, n);
0546
0547 #if N == 1
0548 #define BOOST_TYPE_ERASURE_EXPLICIT explicit
0549 #else
0550 #define BOOST_TYPE_ERASURE_EXPLICIT
0551 #endif
0552
0553 namespace detail {
0554
0555 template<class Concept BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
0556 struct tuple_storage
0557 #if N != BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE
0558 <Concept BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>
0559 #endif
0560 {
0561 #if N
0562 template<class Table BOOST_PP_ENUM_TRAILING_PARAMS(N, class U)>
0563 tuple_storage(
0564 const Table& table BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &u))
0565 :
0566 BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_CONSTRUCT, ~) {}
0567 #else
0568 template<class Table>
0569 explicit tuple_storage(const Table&) {}
0570 #endif
0571 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_TUPLE_MEMBER, `)
0572 };
0573
0574 #if N != BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE
0575
0576 template<class Tuple>
0577 struct get_impl<N, Tuple>
0578 {
0579 typedef any<
0580 typename Tuple::concept_type,
0581 typename Tuple::BOOST_PP_CAT(tag_type, N)
0582 > value_type;
0583 typedef value_type& type;
0584 static type call(Tuple& arg)
0585 { return arg.impl.BOOST_PP_CAT(t, N); }
0586 };
0587
0588 template<class Tuple>
0589 struct get_impl<N, const Tuple>
0590 {
0591 typedef any<
0592 typename Tuple::concept_type,
0593 typename Tuple::BOOST_PP_CAT(tag_type, N)
0594 > value_type;
0595 typedef const value_type& type;
0596 static type call(const Tuple& arg)
0597 { return arg.impl.BOOST_PP_CAT(t, N); }
0598 };
0599
0600 #endif
0601
0602 }
0603
0604 template<class Concept BOOST_PP_ENUM_TRAILING_PARAMS(N, class T)>
0605 class tuple
0606 #if N != BOOST_TYPE_ERASURE_MAX_TUPLE_SIZE
0607 <Concept BOOST_PP_ENUM_TRAILING_PARAMS(N, T)>
0608 #endif
0609 : public tuple_base<tuple<Concept BOOST_PP_ENUM_TRAILING_PARAMS(N, T)> >
0610 {
0611 typedef Concept concept_type;
0612 BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_TAG_TYPEDEF, ~)
0613 public:
0614 typedef ::boost::mpl::int_<N> tuple_size;
0615 #if N
0616 template<BOOST_PP_ENUM_PARAMS(N, class U)>
0617 #endif
0618 BOOST_TYPE_ERASURE_EXPLICIT
0619 tuple(BOOST_PP_ENUM_BINARY_PARAMS(N, U, &u)) :
0620 impl(
0621 ::boost::type_erasure::make_binding<
0622 ::boost::mpl::map<
0623 BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_PAIR, ~)
0624 >
0625 >()
0626 BOOST_PP_ENUM_TRAILING_PARAMS(N, u)
0627 )
0628 {}
0629 #if N
0630 template<BOOST_PP_ENUM_PARAMS(N, class U)>
0631 BOOST_TYPE_ERASURE_EXPLICIT
0632 tuple(BOOST_PP_ENUM_BINARY_PARAMS(N, const U, &u)) :
0633 impl(
0634 ::boost::type_erasure::make_binding<
0635 ::boost::mpl::map<
0636 BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_PAIR, ~)
0637 >
0638 >()
0639 BOOST_PP_ENUM_TRAILING_PARAMS(N, u)
0640 )
0641 {}
0642 #endif
0643 private:
0644 template<int M, class Tuple>
0645 friend struct ::boost::type_erasure::detail::get_impl;
0646 ::boost::type_erasure::detail::tuple_storage<
0647 Concept
0648 BOOST_PP_ENUM_TRAILING_PARAMS(N, T)
0649 > impl;
0650 };
0651
0652 #undef BOOST_TYPE_ERASURE_EXPLICIT
0653 #undef BOOST_TYPE_ERASURE_TUPLE_MEMBER
0654 #undef BOOST_TYPE_ERASURE_CONSTRUCT
0655 #undef BOOST_TYPE_ERASURE_PAIR
0656 #undef BOOST_TYPE_ERASURE_TAG_TYPEDEF
0657 #undef N
0658
0659 #endif