Chris@16
|
1 // (C) Copyright John Maddock 2005.
|
Chris@16
|
2 // Use, modification and distribution are subject to the
|
Chris@16
|
3 // Boost Software License, Version 1.0. (See accompanying file
|
Chris@16
|
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef BOOST_TR1_UTILITY_HPP_INCLUDED
|
Chris@16
|
7 # define BOOST_TR1_UTILITY_HPP_INCLUDED
|
Chris@16
|
8 # include <boost/tr1/detail/config.hpp>
|
Chris@16
|
9
|
Chris@16
|
10 #ifdef BOOST_HAS_TR1_UTILITY
|
Chris@16
|
11
|
Chris@16
|
12 # if defined(BOOST_HAS_INCLUDE_NEXT) && !defined(BOOST_TR1_DISABLE_INCLUDE_NEXT)
|
Chris@16
|
13 # include_next BOOST_TR1_HEADER(utility)
|
Chris@16
|
14 # else
|
Chris@16
|
15 # include <boost/tr1/detail/config_all.hpp>
|
Chris@16
|
16 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(utility))
|
Chris@16
|
17 # endif
|
Chris@16
|
18
|
Chris@16
|
19 #else
|
Chris@16
|
20
|
Chris@16
|
21 #if defined(BOOST_TR1_USE_OLD_TUPLE)
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/type_traits/integral_constant.hpp>
|
Chris@16
|
24 #include <boost/type_traits/add_const.hpp>
|
Chris@16
|
25 #include <boost/type_traits/add_reference.hpp>
|
Chris@16
|
26 #include <boost/mpl/if.hpp>
|
Chris@16
|
27
|
Chris@16
|
28
|
Chris@16
|
29 namespace std{ namespace tr1{
|
Chris@16
|
30
|
Chris@16
|
31 template <class T> struct tuple_size; // forward declaration
|
Chris@16
|
32 template < int I, class T> struct tuple_element; // forward declaration
|
Chris@16
|
33
|
Chris@16
|
34 template <class T1, class T2>
|
Chris@16
|
35 struct tuple_size< ::std::pair<T1, T2> >
|
Chris@16
|
36 : public ::boost::integral_constant< ::std::size_t, 2>
|
Chris@16
|
37 {
|
Chris@16
|
38 };
|
Chris@16
|
39
|
Chris@16
|
40 template <class T1, class T2>
|
Chris@16
|
41 struct tuple_element<0, ::std::pair<T1, T2> >
|
Chris@16
|
42 {
|
Chris@16
|
43 typedef typename std::pair<T1, T2>::first_type type;
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 template <class T1, class T2>
|
Chris@16
|
47 struct tuple_element<1, std::pair<T1, T2> >
|
Chris@16
|
48 {
|
Chris@16
|
49 typedef typename std::pair<T1, T2>::second_type type;
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 namespace tuple_detail{
|
Chris@16
|
53 template <int I, class T1, class T2>
|
Chris@16
|
54 struct tuple_get_result
|
Chris@16
|
55 {
|
Chris@16
|
56 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
|
Chris@16
|
57 typedef typename boost::add_reference<t1>::type type;
|
Chris@16
|
58 };
|
Chris@16
|
59 template <int I, class T1, class T2>
|
Chris@16
|
60 struct const_tuple_get_result
|
Chris@16
|
61 {
|
Chris@16
|
62 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
|
Chris@16
|
63 # if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x582))
|
Chris@16
|
64 // I have absolutely no idea why add_const is not working here for Borland!
|
Chris@16
|
65 // It passes all other free-standing tests, some strange interaction going on
|
Chris@16
|
66 typedef typename boost::add_reference< const t1 >::type type;
|
Chris@16
|
67 # else
|
Chris@16
|
68 typedef typename boost::add_const<t1>::type t2;
|
Chris@16
|
69 typedef typename boost::add_reference<t2>::type type;
|
Chris@16
|
70 # endif
|
Chris@16
|
71 };
|
Chris@16
|
72
|
Chris@16
|
73 template<int I, class T1, class T2>
|
Chris@16
|
74 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::true_type&)
|
Chris@16
|
75 {
|
Chris@16
|
76 return p.first;
|
Chris@16
|
77 }
|
Chris@16
|
78
|
Chris@16
|
79 template<int I, class T1, class T2>
|
Chris@16
|
80 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::true_type&)
|
Chris@16
|
81 {
|
Chris@16
|
82 return p.first;
|
Chris@16
|
83 }
|
Chris@16
|
84
|
Chris@16
|
85 template<int I, class T1, class T2>
|
Chris@16
|
86 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::false_type&)
|
Chris@16
|
87 {
|
Chris@16
|
88 return p.second;
|
Chris@16
|
89 }
|
Chris@16
|
90
|
Chris@16
|
91 template<int I, class T1, class T2>
|
Chris@16
|
92 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::false_type&)
|
Chris@16
|
93 {
|
Chris@16
|
94 return p.second;
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 }
|
Chris@16
|
98
|
Chris@16
|
99 template<int I, class T1, class T2>
|
Chris@16
|
100 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p)
|
Chris@16
|
101 {
|
Chris@16
|
102 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
|
Chris@16
|
103 }
|
Chris@16
|
104
|
Chris@16
|
105 template<int I, class T1, class T2>
|
Chris@16
|
106 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p)
|
Chris@16
|
107 {
|
Chris@16
|
108 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
|
Chris@16
|
109 }
|
Chris@16
|
110
|
Chris@16
|
111 } } // namespaces
|
Chris@16
|
112
|
Chris@16
|
113 #else
|
Chris@16
|
114
|
Chris@16
|
115 #include <boost/tr1/tuple.hpp>
|
Chris@16
|
116
|
Chris@16
|
117 #endif
|
Chris@16
|
118
|
Chris@16
|
119 #endif
|
Chris@16
|
120
|
Chris@16
|
121 #endif
|