]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tr1/include/boost/tr1/utility.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / tr1 / include / boost / tr1 / utility.hpp
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 # if defined(BOOST_HAS_INCLUDE_NEXT) && !defined(BOOST_TR1_DISABLE_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 template <class T1, class T2>
35 struct tuple_size< ::std::pair<T1, T2> >
36 : public ::boost::integral_constant< ::std::size_t, 2>
37 {
38 };
39
40 template <class T1, class T2>
41 struct tuple_element<0, ::std::pair<T1, T2> >
42 {
43 typedef typename std::pair<T1, T2>::first_type type;
44 };
45
46 template <class T1, class T2>
47 struct tuple_element<1, std::pair<T1, T2> >
48 {
49 typedef typename std::pair<T1, T2>::second_type type;
50 };
51
52 namespace tuple_detail{
53 template <int I, class T1, class T2>
54 struct tuple_get_result
55 {
56 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
57 typedef typename boost::add_reference<t1>::type type;
58 };
59 template <int I, class T1, class T2>
60 struct const_tuple_get_result
61 {
62 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
63 # if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x582))
64 // I have absolutely no idea why add_const is not working here for Borland!
65 // It passes all other free-standing tests, some strange interaction going on
66 typedef typename boost::add_reference< const t1 >::type type;
67 # else
68 typedef typename boost::add_const<t1>::type t2;
69 typedef typename boost::add_reference<t2>::type type;
70 # endif
71 };
72
73 template<int I, class T1, class T2>
74 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::true_type&)
75 {
76 return p.first;
77 }
78
79 template<int I, class T1, class T2>
80 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::true_type&)
81 {
82 return p.first;
83 }
84
85 template<int I, class T1, class T2>
86 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::false_type&)
87 {
88 return p.second;
89 }
90
91 template<int I, class T1, class T2>
92 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::false_type&)
93 {
94 return p.second;
95 }
96
97 }
98
99 template<int I, class T1, class T2>
100 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p)
101 {
102 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
103 }
104
105 template<int I, class T1, class T2>
106 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p)
107 {
108 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
109 }
110
111 } } // namespaces
112
113 #else
114
115 #include <boost/tr1/tuple.hpp>
116
117 #endif
118
119 #endif
120
121 #endif