tuple_basic.hpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. // tuple_basic.hpp -----------------------------------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. // Outside help:
  9. // This and that, Gary Powell.
  10. // Fixed return types for get_head/get_tail
  11. // ( and other bugs ) per suggestion of Jens Maurer
  12. // simplified element type accessors + bug fix (Jeremy Siek)
  13. // Several changes/additions according to suggestions by Douglas Gregor,
  14. // William Kempf, Vesa Karvonen, John Max Skaller, Ed Brey, Beman Dawes,
  15. // David Abrahams.
  16. // Revision history:
  17. // 2002 05 01 Hugo Duncan: Fix for Borland after Jaakko's previous changes
  18. // 2002 04 18 Jaakko: tuple element types can be void or plain function
  19. // types, as long as no object is created.
  20. // Tuple objects can no hold even noncopyable types
  21. // such as arrays.
  22. // 2001 10 22 John Maddock
  23. // Fixes for Borland C++
  24. // 2001 08 30 David Abrahams
  25. // Added default constructor for cons<>.
  26. // -----------------------------------------------------------------
  27. #ifndef BOOST_TUPLE_BASIC_HPP
  28. #define BOOST_TUPLE_BASIC_HPP
  29. #include <utility> // needed for the assignment from pair to tuple
  30. #include <boost/type_traits/cv_traits.hpp>
  31. #include <boost/type_traits/function_traits.hpp>
  32. #include <boost/type_traits/integral_constant.hpp>
  33. #include <boost/utility/swap.hpp>
  34. #include <boost/detail/workaround.hpp> // needed for BOOST_WORKAROUND
  35. #if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
  36. #pragma GCC diagnostic push
  37. #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
  38. #endif
  39. namespace boost {
  40. namespace tuples {
  41. // -- null_type --------------------------------------------------------
  42. struct null_type {};
  43. // a helper function to provide a const null_type type temporary
  44. namespace detail {
  45. inline const null_type cnull() { return null_type(); }
  46. // -- if construct ------------------------------------------------
  47. // Proposed by Krzysztof Czarnecki and Ulrich Eisenecker
  48. template <bool If, class Then, class Else> struct IF { typedef Then RET; };
  49. template <class Then, class Else> struct IF<false, Then, Else> {
  50. typedef Else RET;
  51. };
  52. } // end detail
  53. // - cons forward declaration -----------------------------------------------
  54. template <class HT, class TT> struct cons;
  55. // - tuple forward declaration -----------------------------------------------
  56. template <
  57. class T0 = null_type, class T1 = null_type, class T2 = null_type,
  58. class T3 = null_type, class T4 = null_type, class T5 = null_type,
  59. class T6 = null_type, class T7 = null_type, class T8 = null_type,
  60. class T9 = null_type>
  61. class tuple;
  62. // tuple_length forward declaration
  63. template<class T> struct length;
  64. namespace detail {
  65. // -- generate error template, referencing to non-existing members of this
  66. // template is used to produce compilation errors intentionally
  67. template<class T>
  68. class generate_error;
  69. template<int N>
  70. struct drop_front {
  71. template<class Tuple>
  72. struct apply {
  73. typedef BOOST_DEDUCED_TYPENAME drop_front<N-1>::BOOST_NESTED_TEMPLATE
  74. apply<Tuple> next;
  75. typedef BOOST_DEDUCED_TYPENAME next::type::tail_type type;
  76. static const type& call(const Tuple& tup) {
  77. return next::call(tup).tail;
  78. }
  79. };
  80. };
  81. template<>
  82. struct drop_front<0> {
  83. template<class Tuple>
  84. struct apply {
  85. typedef Tuple type;
  86. static const type& call(const Tuple& tup) {
  87. return tup;
  88. }
  89. };
  90. };
  91. } // end of namespace detail
  92. // -cons type accessors ----------------------------------------
  93. // typename tuples::element<N,T>::type gets the type of the
  94. // Nth element ot T, first element is at index 0
  95. // -------------------------------------------------------
  96. #ifndef BOOST_NO_CV_SPECIALIZATIONS
  97. template<int N, class T>
  98. struct element
  99. {
  100. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  101. apply<T>::type::head_type type;
  102. };
  103. template<int N, class T>
  104. struct element<N, const T>
  105. {
  106. private:
  107. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  108. apply<T>::type::head_type unqualified_type;
  109. public:
  110. #if BOOST_WORKAROUND(BOOST_BORLANDC,<0x600)
  111. typedef const unqualified_type type;
  112. #else
  113. typedef BOOST_DEDUCED_TYPENAME boost::add_const<unqualified_type>::type type;
  114. #endif
  115. };
  116. #else // def BOOST_NO_CV_SPECIALIZATIONS
  117. namespace detail {
  118. template<int N, class T, bool IsConst>
  119. struct element_impl
  120. {
  121. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  122. apply<T>::type::head_type type;
  123. };
  124. template<int N, class T>
  125. struct element_impl<N, T, true /* IsConst */>
  126. {
  127. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  128. apply<T>::type::head_type unqualified_type;
  129. typedef const unqualified_type type;
  130. };
  131. } // end of namespace detail
  132. template<int N, class T>
  133. struct element:
  134. public detail::element_impl<N, T, ::boost::is_const<T>::value>
  135. {
  136. };
  137. #endif
  138. // -get function templates -----------------------------------------------
  139. // Usage: get<N>(aTuple)
  140. // -- some traits classes for get functions
  141. // access traits lifted from detail namespace to be part of the interface,
  142. // (Joel de Guzman's suggestion). Rationale: get functions are part of the
  143. // interface, so should the way to express their return types be.
  144. template <class T> struct access_traits {
  145. typedef const T& const_type;
  146. typedef T& non_const_type;
  147. typedef const typename boost::remove_cv<T>::type& parameter_type;
  148. // used as the tuple constructors parameter types
  149. // Rationale: non-reference tuple element types can be cv-qualified.
  150. // It should be possible to initialize such types with temporaries,
  151. // and when binding temporaries to references, the reference must
  152. // be non-volatile and const. 8.5.3. (5)
  153. };
  154. template <class T> struct access_traits<T&> {
  155. typedef T& const_type;
  156. typedef T& non_const_type;
  157. typedef T& parameter_type;
  158. };
  159. // get function for non-const cons-lists, returns a reference to the element
  160. template<int N, class HT, class TT>
  161. inline typename access_traits<
  162. typename element<N, cons<HT, TT> >::type
  163. >::non_const_type
  164. get(cons<HT, TT>& c) {
  165. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  166. apply<cons<HT, TT> > impl;
  167. typedef BOOST_DEDUCED_TYPENAME impl::type cons_element;
  168. return const_cast<cons_element&>(impl::call(c)).head;
  169. }
  170. // get function for const cons-lists, returns a const reference to
  171. // the element. If the element is a reference, returns the reference
  172. // as such (that is, can return a non-const reference)
  173. template<int N, class HT, class TT>
  174. inline typename access_traits<
  175. typename element<N, cons<HT, TT> >::type
  176. >::const_type
  177. get(const cons<HT, TT>& c) {
  178. typedef BOOST_DEDUCED_TYPENAME detail::drop_front<N>::BOOST_NESTED_TEMPLATE
  179. apply<cons<HT, TT> > impl;
  180. return impl::call(c).head;
  181. }
  182. // -- the cons template --------------------------------------------------
  183. namespace detail {
  184. // These helper templates wrap void types and plain function types.
  185. // The reationale is to allow one to write tuple types with those types
  186. // as elements, even though it is not possible to instantiate such object.
  187. // E.g: typedef tuple<void> some_type; // ok
  188. // but: some_type x; // fails
  189. template <class T> class non_storeable_type {
  190. non_storeable_type();
  191. };
  192. template <class T> struct wrap_non_storeable_type {
  193. typedef typename IF<
  194. ::boost::is_function<T>::value, non_storeable_type<T>, T
  195. >::RET type;
  196. };
  197. template <> struct wrap_non_storeable_type<void> {
  198. typedef non_storeable_type<void> type;
  199. };
  200. } // detail
  201. template <class HT, class TT>
  202. struct cons {
  203. typedef HT head_type;
  204. typedef TT tail_type;
  205. typedef typename
  206. detail::wrap_non_storeable_type<head_type>::type stored_head_type;
  207. stored_head_type head;
  208. tail_type tail;
  209. typename access_traits<stored_head_type>::non_const_type
  210. get_head() { return head; }
  211. typename access_traits<tail_type>::non_const_type
  212. get_tail() { return tail; }
  213. typename access_traits<stored_head_type>::const_type
  214. get_head() const { return head; }
  215. typename access_traits<tail_type>::const_type
  216. get_tail() const { return tail; }
  217. cons() : head(), tail() {}
  218. // cons() : head(detail::default_arg<HT>::f()), tail() {}
  219. // the argument for head is not strictly needed, but it prevents
  220. // array type elements. This is good, since array type elements
  221. // cannot be supported properly in any case (no assignment,
  222. // copy works only if the tails are exactly the same type, ...)
  223. cons(typename access_traits<stored_head_type>::parameter_type h,
  224. const tail_type& t)
  225. : head (h), tail(t) {}
  226. template <class T1, class T2, class T3, class T4, class T5,
  227. class T6, class T7, class T8, class T9, class T10>
  228. cons( T1& t1, T2& t2, T3& t3, T4& t4, T5& t5,
  229. T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
  230. : head (t1),
  231. tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
  232. {}
  233. template <class T2, class T3, class T4, class T5,
  234. class T6, class T7, class T8, class T9, class T10>
  235. cons( const null_type& /*t1*/, T2& t2, T3& t3, T4& t4, T5& t5,
  236. T6& t6, T7& t7, T8& t8, T9& t9, T10& t10 )
  237. : head (),
  238. tail (t2, t3, t4, t5, t6, t7, t8, t9, t10, detail::cnull())
  239. {}
  240. cons( const cons& u ) : head(u.head), tail(u.tail) {}
  241. template <class HT2, class TT2>
  242. cons( const cons<HT2, TT2>& u ) : head(u.head), tail(u.tail) {}
  243. template <class HT2, class TT2>
  244. cons& operator=( const cons<HT2, TT2>& u ) {
  245. head=u.head; tail=u.tail; return *this;
  246. }
  247. // must define assignment operator explicitly, implicit version is
  248. // illformed if HT is a reference (12.8. (12))
  249. cons& operator=(const cons& u) {
  250. head = u.head; tail = u.tail; return *this;
  251. }
  252. template <class T1, class T2>
  253. cons& operator=( const std::pair<T1, T2>& u ) {
  254. BOOST_STATIC_ASSERT(length<cons>::value == 2); // check length = 2
  255. head = u.first; tail.head = u.second; return *this;
  256. }
  257. // get member functions (non-const and const)
  258. template <int N>
  259. typename access_traits<
  260. typename element<N, cons<HT, TT> >::type
  261. >::non_const_type
  262. get() {
  263. return boost::tuples::get<N>(*this); // delegate to non-member get
  264. }
  265. template <int N>
  266. typename access_traits<
  267. typename element<N, cons<HT, TT> >::type
  268. >::const_type
  269. get() const {
  270. return boost::tuples::get<N>(*this); // delegate to non-member get
  271. }
  272. };
  273. template <class HT>
  274. struct cons<HT, null_type> {
  275. typedef HT head_type;
  276. typedef null_type tail_type;
  277. typedef cons<HT, null_type> self_type;
  278. typedef typename
  279. detail::wrap_non_storeable_type<head_type>::type stored_head_type;
  280. stored_head_type head;
  281. typename access_traits<stored_head_type>::non_const_type
  282. get_head() { return head; }
  283. null_type get_tail() { return null_type(); }
  284. typename access_traits<stored_head_type>::const_type
  285. get_head() const { return head; }
  286. const null_type get_tail() const { return null_type(); }
  287. // cons() : head(detail::default_arg<HT>::f()) {}
  288. cons() : head() {}
  289. cons(typename access_traits<stored_head_type>::parameter_type h,
  290. const null_type& = null_type())
  291. : head (h) {}
  292. template<class T1>
  293. cons(T1& t1, const null_type&, const null_type&, const null_type&,
  294. const null_type&, const null_type&, const null_type&,
  295. const null_type&, const null_type&, const null_type&)
  296. : head (t1) {}
  297. cons(const null_type&,
  298. const null_type&, const null_type&, const null_type&,
  299. const null_type&, const null_type&, const null_type&,
  300. const null_type&, const null_type&, const null_type&)
  301. : head () {}
  302. cons( const cons& u ) : head(u.head) {}
  303. template <class HT2>
  304. cons( const cons<HT2, null_type>& u ) : head(u.head) {}
  305. template <class HT2>
  306. cons& operator=(const cons<HT2, null_type>& u )
  307. { head = u.head; return *this; }
  308. // must define assignment operator explicitely, implicit version
  309. // is illformed if HT is a reference
  310. cons& operator=(const cons& u) { head = u.head; return *this; }
  311. template <int N>
  312. typename access_traits<
  313. typename element<N, self_type>::type
  314. >::non_const_type
  315. get() {
  316. return boost::tuples::get<N>(*this);
  317. }
  318. template <int N>
  319. typename access_traits<
  320. typename element<N, self_type>::type
  321. >::const_type
  322. get() const {
  323. return boost::tuples::get<N>(*this);
  324. }
  325. };
  326. // templates for finding out the length of the tuple -------------------
  327. template<class T>
  328. struct length: boost::integral_constant<int, 1 + length<typename T::tail_type>::value>
  329. {
  330. };
  331. template<>
  332. struct length<tuple<> >: boost::integral_constant<int, 0>
  333. {
  334. };
  335. template<>
  336. struct length<tuple<> const>: boost::integral_constant<int, 0>
  337. {
  338. };
  339. template<>
  340. struct length<null_type>: boost::integral_constant<int, 0>
  341. {
  342. };
  343. template<>
  344. struct length<null_type const>: boost::integral_constant<int, 0>
  345. {
  346. };
  347. namespace detail {
  348. // Tuple to cons mapper --------------------------------------------------
  349. template <class T0, class T1, class T2, class T3, class T4,
  350. class T5, class T6, class T7, class T8, class T9>
  351. struct map_tuple_to_cons
  352. {
  353. typedef cons<T0,
  354. typename map_tuple_to_cons<T1, T2, T3, T4, T5,
  355. T6, T7, T8, T9, null_type>::type
  356. > type;
  357. };
  358. // The empty tuple is a null_type
  359. template <>
  360. struct map_tuple_to_cons<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type>
  361. {
  362. typedef null_type type;
  363. };
  364. } // end detail
  365. // -------------------------------------------------------------------
  366. // -- tuple ------------------------------------------------------
  367. template <class T0, class T1, class T2, class T3, class T4,
  368. class T5, class T6, class T7, class T8, class T9>
  369. class tuple :
  370. public detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
  371. {
  372. public:
  373. typedef typename
  374. detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited;
  375. typedef typename inherited::head_type head_type;
  376. typedef typename inherited::tail_type tail_type;
  377. // access_traits<T>::parameter_type takes non-reference types as const T&
  378. tuple() {}
  379. explicit tuple(typename access_traits<T0>::parameter_type t0)
  380. : inherited(t0, detail::cnull(), detail::cnull(), detail::cnull(),
  381. detail::cnull(), detail::cnull(), detail::cnull(),
  382. detail::cnull(), detail::cnull(), detail::cnull()) {}
  383. tuple(typename access_traits<T0>::parameter_type t0,
  384. typename access_traits<T1>::parameter_type t1)
  385. : inherited(t0, t1, detail::cnull(), detail::cnull(),
  386. detail::cnull(), detail::cnull(), detail::cnull(),
  387. detail::cnull(), detail::cnull(), detail::cnull()) {}
  388. tuple(typename access_traits<T0>::parameter_type t0,
  389. typename access_traits<T1>::parameter_type t1,
  390. typename access_traits<T2>::parameter_type t2)
  391. : inherited(t0, t1, t2, detail::cnull(), detail::cnull(),
  392. detail::cnull(), detail::cnull(), detail::cnull(),
  393. detail::cnull(), detail::cnull()) {}
  394. tuple(typename access_traits<T0>::parameter_type t0,
  395. typename access_traits<T1>::parameter_type t1,
  396. typename access_traits<T2>::parameter_type t2,
  397. typename access_traits<T3>::parameter_type t3)
  398. : inherited(t0, t1, t2, t3, detail::cnull(), detail::cnull(),
  399. detail::cnull(), detail::cnull(), detail::cnull(),
  400. detail::cnull()) {}
  401. tuple(typename access_traits<T0>::parameter_type t0,
  402. typename access_traits<T1>::parameter_type t1,
  403. typename access_traits<T2>::parameter_type t2,
  404. typename access_traits<T3>::parameter_type t3,
  405. typename access_traits<T4>::parameter_type t4)
  406. : inherited(t0, t1, t2, t3, t4, detail::cnull(), detail::cnull(),
  407. detail::cnull(), detail::cnull(), detail::cnull()) {}
  408. tuple(typename access_traits<T0>::parameter_type t0,
  409. typename access_traits<T1>::parameter_type t1,
  410. typename access_traits<T2>::parameter_type t2,
  411. typename access_traits<T3>::parameter_type t3,
  412. typename access_traits<T4>::parameter_type t4,
  413. typename access_traits<T5>::parameter_type t5)
  414. : inherited(t0, t1, t2, t3, t4, t5, detail::cnull(), detail::cnull(),
  415. detail::cnull(), detail::cnull()) {}
  416. tuple(typename access_traits<T0>::parameter_type t0,
  417. typename access_traits<T1>::parameter_type t1,
  418. typename access_traits<T2>::parameter_type t2,
  419. typename access_traits<T3>::parameter_type t3,
  420. typename access_traits<T4>::parameter_type t4,
  421. typename access_traits<T5>::parameter_type t5,
  422. typename access_traits<T6>::parameter_type t6)
  423. : inherited(t0, t1, t2, t3, t4, t5, t6, detail::cnull(),
  424. detail::cnull(), detail::cnull()) {}
  425. tuple(typename access_traits<T0>::parameter_type t0,
  426. typename access_traits<T1>::parameter_type t1,
  427. typename access_traits<T2>::parameter_type t2,
  428. typename access_traits<T3>::parameter_type t3,
  429. typename access_traits<T4>::parameter_type t4,
  430. typename access_traits<T5>::parameter_type t5,
  431. typename access_traits<T6>::parameter_type t6,
  432. typename access_traits<T7>::parameter_type t7)
  433. : inherited(t0, t1, t2, t3, t4, t5, t6, t7, detail::cnull(),
  434. detail::cnull()) {}
  435. tuple(typename access_traits<T0>::parameter_type t0,
  436. typename access_traits<T1>::parameter_type t1,
  437. typename access_traits<T2>::parameter_type t2,
  438. typename access_traits<T3>::parameter_type t3,
  439. typename access_traits<T4>::parameter_type t4,
  440. typename access_traits<T5>::parameter_type t5,
  441. typename access_traits<T6>::parameter_type t6,
  442. typename access_traits<T7>::parameter_type t7,
  443. typename access_traits<T8>::parameter_type t8)
  444. : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, detail::cnull()) {}
  445. tuple(typename access_traits<T0>::parameter_type t0,
  446. typename access_traits<T1>::parameter_type t1,
  447. typename access_traits<T2>::parameter_type t2,
  448. typename access_traits<T3>::parameter_type t3,
  449. typename access_traits<T4>::parameter_type t4,
  450. typename access_traits<T5>::parameter_type t5,
  451. typename access_traits<T6>::parameter_type t6,
  452. typename access_traits<T7>::parameter_type t7,
  453. typename access_traits<T8>::parameter_type t8,
  454. typename access_traits<T9>::parameter_type t9)
  455. : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {}
  456. template<class U1, class U2>
  457. tuple(const cons<U1, U2>& p) : inherited(p) {}
  458. template <class U1, class U2>
  459. tuple& operator=(const cons<U1, U2>& k) {
  460. inherited::operator=(k);
  461. return *this;
  462. }
  463. template <class U1, class U2>
  464. tuple& operator=(const std::pair<U1, U2>& k) {
  465. BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
  466. this->head = k.first;
  467. this->tail.head = k.second;
  468. return *this;
  469. }
  470. };
  471. // The empty tuple
  472. template <>
  473. class tuple<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type> :
  474. public null_type
  475. {
  476. public:
  477. typedef null_type inherited;
  478. };
  479. // Swallows any assignment (by Doug Gregor)
  480. namespace detail {
  481. struct swallow_assign;
  482. typedef void (detail::swallow_assign::*ignore_t)();
  483. struct swallow_assign {
  484. swallow_assign(ignore_t(*)(ignore_t)) {}
  485. template<typename T>
  486. swallow_assign const& operator=(const T&) const {
  487. return *this;
  488. }
  489. };
  490. } // namespace detail
  491. // "ignore" allows tuple positions to be ignored when using "tie".
  492. inline detail::ignore_t ignore(detail::ignore_t) { return 0; }
  493. // ---------------------------------------------------------------------------
  494. // The call_traits for make_tuple
  495. // Honours the reference_wrapper class.
  496. // Must be instantiated with plain or const plain types (not with references)
  497. // from template<class T> foo(const T& t) : make_tuple_traits<const T>::type
  498. // from template<class T> foo(T& t) : make_tuple_traits<T>::type
  499. // Conversions:
  500. // T -> T,
  501. // references -> compile_time_error
  502. // reference_wrapper<T> -> T&
  503. // const reference_wrapper<T> -> T&
  504. // array -> const ref array
  505. template<class T>
  506. struct make_tuple_traits {
  507. typedef T type;
  508. // commented away, see below (JJ)
  509. // typedef typename IF<
  510. // boost::is_function<T>::value,
  511. // T&,
  512. // T>::RET type;
  513. };
  514. // The is_function test was there originally for plain function types,
  515. // which can't be stored as such (we must either store them as references or
  516. // pointers). Such a type could be formed if make_tuple was called with a
  517. // reference to a function.
  518. // But this would mean that a const qualified function type was formed in
  519. // the make_tuple function and hence make_tuple can't take a function
  520. // reference as a parameter, and thus T can't be a function type.
  521. // So is_function test was removed.
  522. // (14.8.3. says that type deduction fails if a cv-qualified function type
  523. // is created. (It only applies for the case of explicitly specifying template
  524. // args, though?)) (JJ)
  525. template<class T>
  526. struct make_tuple_traits<T&> {
  527. typedef typename
  528. detail::generate_error<T&>::
  529. do_not_use_with_reference_type error;
  530. };
  531. // Arrays can't be stored as plain types; convert them to references.
  532. // All arrays are converted to const. This is because make_tuple takes its
  533. // parameters as const T& and thus the knowledge of the potential
  534. // non-constness of actual argument is lost.
  535. template<class T, int n> struct make_tuple_traits <T[n]> {
  536. typedef const T (&type)[n];
  537. };
  538. template<class T, int n>
  539. struct make_tuple_traits<const T[n]> {
  540. typedef const T (&type)[n];
  541. };
  542. template<class T, int n> struct make_tuple_traits<volatile T[n]> {
  543. typedef const volatile T (&type)[n];
  544. };
  545. template<class T, int n>
  546. struct make_tuple_traits<const volatile T[n]> {
  547. typedef const volatile T (&type)[n];
  548. };
  549. template<class T>
  550. struct make_tuple_traits<reference_wrapper<T> >{
  551. typedef T& type;
  552. };
  553. template<class T>
  554. struct make_tuple_traits<const reference_wrapper<T> >{
  555. typedef T& type;
  556. };
  557. template<>
  558. struct make_tuple_traits<detail::ignore_t(detail::ignore_t)> {
  559. typedef detail::swallow_assign type;
  560. };
  561. namespace detail {
  562. // a helper traits to make the make_tuple functions shorter (Vesa Karvonen's
  563. // suggestion)
  564. template <
  565. class T0 = null_type, class T1 = null_type, class T2 = null_type,
  566. class T3 = null_type, class T4 = null_type, class T5 = null_type,
  567. class T6 = null_type, class T7 = null_type, class T8 = null_type,
  568. class T9 = null_type
  569. >
  570. struct make_tuple_mapper {
  571. typedef
  572. tuple<typename make_tuple_traits<T0>::type,
  573. typename make_tuple_traits<T1>::type,
  574. typename make_tuple_traits<T2>::type,
  575. typename make_tuple_traits<T3>::type,
  576. typename make_tuple_traits<T4>::type,
  577. typename make_tuple_traits<T5>::type,
  578. typename make_tuple_traits<T6>::type,
  579. typename make_tuple_traits<T7>::type,
  580. typename make_tuple_traits<T8>::type,
  581. typename make_tuple_traits<T9>::type> type;
  582. };
  583. } // end detail
  584. // -make_tuple function templates -----------------------------------
  585. inline tuple<> make_tuple() {
  586. return tuple<>();
  587. }
  588. template<class T0>
  589. inline typename detail::make_tuple_mapper<T0>::type
  590. make_tuple(const T0& t0) {
  591. typedef typename detail::make_tuple_mapper<T0>::type t;
  592. return t(t0);
  593. }
  594. template<class T0, class T1>
  595. inline typename detail::make_tuple_mapper<T0, T1>::type
  596. make_tuple(const T0& t0, const T1& t1) {
  597. typedef typename detail::make_tuple_mapper<T0, T1>::type t;
  598. return t(t0, t1);
  599. }
  600. template<class T0, class T1, class T2>
  601. inline typename detail::make_tuple_mapper<T0, T1, T2>::type
  602. make_tuple(const T0& t0, const T1& t1, const T2& t2) {
  603. typedef typename detail::make_tuple_mapper<T0, T1, T2>::type t;
  604. return t(t0, t1, t2);
  605. }
  606. template<class T0, class T1, class T2, class T3>
  607. inline typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
  608. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3) {
  609. typedef typename detail::make_tuple_mapper<T0, T1, T2, T3>::type t;
  610. return t(t0, t1, t2, t3);
  611. }
  612. template<class T0, class T1, class T2, class T3, class T4>
  613. inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
  614. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  615. const T4& t4) {
  616. typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type t;
  617. return t(t0, t1, t2, t3, t4);
  618. }
  619. template<class T0, class T1, class T2, class T3, class T4, class T5>
  620. inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
  621. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  622. const T4& t4, const T5& t5) {
  623. typedef typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type t;
  624. return t(t0, t1, t2, t3, t4, t5);
  625. }
  626. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
  627. inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type
  628. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  629. const T4& t4, const T5& t5, const T6& t6) {
  630. typedef typename detail::make_tuple_mapper
  631. <T0, T1, T2, T3, T4, T5, T6>::type t;
  632. return t(t0, t1, t2, t3, t4, t5, t6);
  633. }
  634. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  635. class T7>
  636. inline typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
  637. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  638. const T4& t4, const T5& t5, const T6& t6, const T7& t7) {
  639. typedef typename detail::make_tuple_mapper
  640. <T0, T1, T2, T3, T4, T5, T6, T7>::type t;
  641. return t(t0, t1, t2, t3, t4, t5, t6, t7);
  642. }
  643. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  644. class T7, class T8>
  645. inline typename detail::make_tuple_mapper
  646. <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
  647. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  648. const T4& t4, const T5& t5, const T6& t6, const T7& t7,
  649. const T8& t8) {
  650. typedef typename detail::make_tuple_mapper
  651. <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type t;
  652. return t(t0, t1, t2, t3, t4, t5, t6, t7, t8);
  653. }
  654. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  655. class T7, class T8, class T9>
  656. inline typename detail::make_tuple_mapper
  657. <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
  658. make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3,
  659. const T4& t4, const T5& t5, const T6& t6, const T7& t7,
  660. const T8& t8, const T9& t9) {
  661. typedef typename detail::make_tuple_mapper
  662. <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type t;
  663. return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
  664. }
  665. namespace detail {
  666. template<class T>
  667. struct tie_traits {
  668. typedef T& type;
  669. };
  670. template<>
  671. struct tie_traits<ignore_t(ignore_t)> {
  672. typedef swallow_assign type;
  673. };
  674. template<>
  675. struct tie_traits<void> {
  676. typedef null_type type;
  677. };
  678. template <
  679. class T0 = void, class T1 = void, class T2 = void,
  680. class T3 = void, class T4 = void, class T5 = void,
  681. class T6 = void, class T7 = void, class T8 = void,
  682. class T9 = void
  683. >
  684. struct tie_mapper {
  685. typedef
  686. tuple<typename tie_traits<T0>::type,
  687. typename tie_traits<T1>::type,
  688. typename tie_traits<T2>::type,
  689. typename tie_traits<T3>::type,
  690. typename tie_traits<T4>::type,
  691. typename tie_traits<T5>::type,
  692. typename tie_traits<T6>::type,
  693. typename tie_traits<T7>::type,
  694. typename tie_traits<T8>::type,
  695. typename tie_traits<T9>::type> type;
  696. };
  697. }
  698. // Tie function templates -------------------------------------------------
  699. template<class T0>
  700. inline typename detail::tie_mapper<T0>::type
  701. tie(T0& t0) {
  702. typedef typename detail::tie_mapper<T0>::type t;
  703. return t(t0);
  704. }
  705. template<class T0, class T1>
  706. inline typename detail::tie_mapper<T0, T1>::type
  707. tie(T0& t0, T1& t1) {
  708. typedef typename detail::tie_mapper<T0, T1>::type t;
  709. return t(t0, t1);
  710. }
  711. template<class T0, class T1, class T2>
  712. inline typename detail::tie_mapper<T0, T1, T2>::type
  713. tie(T0& t0, T1& t1, T2& t2) {
  714. typedef typename detail::tie_mapper<T0, T1, T2>::type t;
  715. return t(t0, t1, t2);
  716. }
  717. template<class T0, class T1, class T2, class T3>
  718. inline typename detail::tie_mapper<T0, T1, T2, T3>::type
  719. tie(T0& t0, T1& t1, T2& t2, T3& t3) {
  720. typedef typename detail::tie_mapper<T0, T1, T2, T3>::type t;
  721. return t(t0, t1, t2, t3);
  722. }
  723. template<class T0, class T1, class T2, class T3, class T4>
  724. inline typename detail::tie_mapper<T0, T1, T2, T3, T4>::type
  725. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  726. T4& t4) {
  727. typedef typename detail::tie_mapper<T0, T1, T2, T3, T4>::type t;
  728. return t(t0, t1, t2, t3, t4);
  729. }
  730. template<class T0, class T1, class T2, class T3, class T4, class T5>
  731. inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5>::type
  732. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  733. T4& t4, T5& t5) {
  734. typedef typename detail::tie_mapper<T0, T1, T2, T3, T4, T5>::type t;
  735. return t(t0, t1, t2, t3, t4, t5);
  736. }
  737. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
  738. inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5, T6>::type
  739. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  740. T4& t4, T5& t5, T6& t6) {
  741. typedef typename detail::tie_mapper
  742. <T0, T1, T2, T3, T4, T5, T6>::type t;
  743. return t(t0, t1, t2, t3, t4, t5, t6);
  744. }
  745. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  746. class T7>
  747. inline typename detail::tie_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
  748. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  749. T4& t4, T5& t5, T6& t6, T7& t7) {
  750. typedef typename detail::tie_mapper
  751. <T0, T1, T2, T3, T4, T5, T6, T7>::type t;
  752. return t(t0, t1, t2, t3, t4, t5, t6, t7);
  753. }
  754. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  755. class T7, class T8>
  756. inline typename detail::tie_mapper
  757. <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
  758. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  759. T4& t4, T5& t5, T6& t6, T7& t7,
  760. T8& t8) {
  761. typedef typename detail::tie_mapper
  762. <T0, T1, T2, T3, T4, T5, T6, T7, T8>::type t;
  763. return t(t0, t1, t2, t3, t4, t5, t6, t7, t8);
  764. }
  765. template<class T0, class T1, class T2, class T3, class T4, class T5, class T6,
  766. class T7, class T8, class T9>
  767. inline typename detail::tie_mapper
  768. <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
  769. tie(T0& t0, T1& t1, T2& t2, T3& t3,
  770. T4& t4, T5& t5, T6& t6, T7& t7,
  771. T8& t8, T9& t9) {
  772. typedef typename detail::tie_mapper
  773. <T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type t;
  774. return t(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
  775. }
  776. template <class T0, class T1, class T2, class T3, class T4,
  777. class T5, class T6, class T7, class T8, class T9>
  778. void swap(tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& lhs,
  779. tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& rhs);
  780. inline void swap(null_type&, null_type&) {}
  781. template<class HH>
  782. inline void swap(cons<HH, null_type>& lhs, cons<HH, null_type>& rhs) {
  783. ::boost::swap(lhs.head, rhs.head);
  784. }
  785. template<class HH, class TT>
  786. inline void swap(cons<HH, TT>& lhs, cons<HH, TT>& rhs) {
  787. ::boost::swap(lhs.head, rhs.head);
  788. ::boost::tuples::swap(lhs.tail, rhs.tail);
  789. }
  790. template <class T0, class T1, class T2, class T3, class T4,
  791. class T5, class T6, class T7, class T8, class T9>
  792. inline void swap(tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& lhs,
  793. tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>& rhs) {
  794. typedef tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> tuple_type;
  795. typedef typename tuple_type::inherited base;
  796. ::boost::tuples::swap(static_cast<base&>(lhs), static_cast<base&>(rhs));
  797. }
  798. } // end of namespace tuples
  799. } // end of namespace boost
  800. #if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
  801. #pragma GCC diagnostic pop
  802. #endif
  803. #endif // BOOST_TUPLE_BASIC_HPP