Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/tr1/utility.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 3.3 KB
Line 
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_STD_HEADER(BOOST_TR1_PATH(utility))
16#  endif
17
18#else
19
20#if defined(BOOST_TR1_USE_OLD_TUPLE)
21
22#include <boost/type_traits/integral_constant.hpp>
23#include <boost/type_traits/add_const.hpp>
24#include <boost/type_traits/add_reference.hpp>
25#include <boost/mpl/if.hpp>
26
27
28namespace std{ namespace tr1{
29
30template <class T> struct tuple_size; // forward declaration
31template < int I, class T> struct tuple_element; // forward declaration
32
33#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
34template <class T1, class T2>
35struct tuple_size< ::std::pair<T1, T2> >
36   : public ::boost::integral_constant< ::std::size_t, 2>
37{
38};
39
40template <class T1, class T2>
41struct tuple_element<0, ::std::pair<T1, T2> >
42{
43   typedef typename std::pair<T1, T2>::first_type type;
44};
45
46template <class T1, class T2>
47struct tuple_element<1, std::pair<T1, T2> >
48{
49   typedef typename std::pair<T1, T2>::second_type type;
50};
51#endif
52
53namespace tuple_detail{
54   template <int I, class T1, class T2>
55   struct tuple_get_result
56   {
57      typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
58      typedef typename boost::add_reference<t1>::type type;
59   };
60   template <int I, class T1, class T2>
61   struct const_tuple_get_result
62   {
63      typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
64# if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x582))
65      // I have absolutely no idea why add_const is not working here for Borland!
66      // It passes all other free-standing tests, some strange interaction going on
67      typedef typename boost::add_reference< const t1 >::type type;
68# else
69      typedef typename boost::add_const<t1>::type t2;
70      typedef typename boost::add_reference<t2>::type type;
71# endif
72   };
73
74template<int I, class T1, class T2>
75inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::true_type&)
76{
77   return p.first;
78}
79
80template<int I, class T1, class T2>
81inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::true_type&)
82{
83   return p.first;
84}
85
86template<int I, class T1, class T2>
87inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::false_type&)
88{
89   return p.second;
90}
91
92template<int I, class T1, class T2>
93inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::false_type&)
94{
95   return p.second;
96}
97
98}
99
100template<int I, class T1, class T2> 
101inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p)
102{
103   return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
104}
105
106template<int I, class T1, class T2> 
107inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p)
108{
109   return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
110}
111
112} } // namespaces
113
114#else
115
116#include <boost/tr1/tuple.hpp>
117
118#endif
119
120#endif
121
122#endif
Note: See TracBrowser for help on using the repository browser.