First public contribution.
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 # ifdef BOOST_HAS_INCLUDE_NEXT
13 # include_next BOOST_TR1_HEADER(utility)
15 # include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(utility))
20 #if defined(BOOST_TR1_USE_OLD_TUPLE)
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>
28 namespace std{ namespace tr1{
30 template <class T> struct tuple_size; // forward declaration
31 template < int I, class T> struct tuple_element; // forward declaration
33 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
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;
53 namespace tuple_detail{
54 template <int I, class T1, class T2>
55 struct tuple_get_result
57 typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
58 typedef typename boost::add_reference<t1>::type type;
60 template <int I, class T1, class T2>
61 struct const_tuple_get_result
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;
69 typedef typename boost::add_const<t1>::type t2;
70 typedef typename boost::add_reference<t2>::type type;
74 template<int I, class T1, class T2>
75 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::true_type&)
80 template<int I, class T1, class T2>
81 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::true_type&)
86 template<int I, class T1, class T2>
87 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::false_type&)
92 template<int I, class T1, class T2>
93 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::false_type&)
100 template<int I, class T1, class T2>
101 inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p)
103 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
106 template<int I, class T1, class T2>
107 inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p)
109 return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
116 #include <boost/tr1/tuple.hpp>