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)
6 #ifndef BOOST_TR1_UTILITY_HPP_INCLUDED
7 # define BOOST_TR1_UTILITY_HPP_INCLUDED
8 # include <boost/tr1/detail/config.hpp>
10 #ifdef BOOST_HAS_TR1_UTILITY
12 # if defined(BOOST_HAS_INCLUDE_NEXT) && !defined(BOOST_TR1_DISABLE_INCLUDE_NEXT)
13 # include_next BOOST_TR1_HEADER(utility)
15 # include <boost/tr1/detail/config_all.hpp>
16 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(utility))
21 #if defined(BOOST_TR1_USE_OLD_TUPLE)
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>
29 namespace std{ namespace tr1{
31 template <class T> struct tuple_size; // forward declaration
32 template < int I, class T> struct tuple_element; // forward declaration
34 template <class T1, class T2>
35 struct tuple_size< ::std::pair<T1, T2> >
36 : public ::boost::integral_constant< ::std::size_t, 2>
40 template <class T1, class T2>
41 struct tuple_element<0, ::std::pair<T1, T2> >
43 typedef typename std::pair<T1, T2>::first_type type;
46 template <class T1, class T2>
47 struct tuple_element<1, std::pair<T1, T2> >
49 typedef typename std::pair<T1, T2>::second_type type;
52 namespace tuple_detail{
53 template <int I, class T1, class T2>
54 struct tuple_get_result
56 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
57 typedef typename boost::add_reference<t1>::type type;
59 template <int I, class T1, class T2>
60 struct const_tuple_get_result
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;
68 typedef typename boost::add_const<t1>::type t2;
69 typedef typename boost::add_reference<t2>::type type;
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&)
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&)
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&)
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&)
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)
102 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
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)
108 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
115 #include <boost/tr1/tuple.hpp>