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