| [29] | 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 |  | 
|---|
 | 28 | namespace std{ namespace tr1{ | 
|---|
 | 29 |  | 
|---|
 | 30 | template <class T> struct tuple_size; // forward declaration | 
|---|
 | 31 | template < int I, class T> struct tuple_element; // forward declaration | 
|---|
 | 32 |  | 
|---|
 | 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> | 
|---|
 | 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 | #endif | 
|---|
 | 52 |  | 
|---|
 | 53 | namespace 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 |  | 
|---|
 | 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&) | 
|---|
 | 76 | { | 
|---|
 | 77 |    return p.first; | 
|---|
 | 78 | } | 
|---|
 | 79 |  | 
|---|
 | 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&) | 
|---|
 | 82 | { | 
|---|
 | 83 |    return p.first; | 
|---|
 | 84 | } | 
|---|
 | 85 |  | 
|---|
 | 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&) | 
|---|
 | 88 | { | 
|---|
 | 89 |    return p.second; | 
|---|
 | 90 | } | 
|---|
 | 91 |  | 
|---|
 | 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&) | 
|---|
 | 94 | { | 
|---|
 | 95 |    return p.second; | 
|---|
 | 96 | } | 
|---|
 | 97 |  | 
|---|
 | 98 | } | 
|---|
 | 99 |  | 
|---|
 | 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) | 
|---|
 | 102 | { | 
|---|
 | 103 |    return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>()); | 
|---|
 | 104 | } | 
|---|
 | 105 |  | 
|---|
 | 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) | 
|---|
 | 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 | 
|---|