os/ossrv/ossrv_pub/boost_apis/boost/tr1/utility.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//  (C) Copyright John Maddock 2005.
sl@0
     2
//  Use, modification and distribution are subject to the
sl@0
     3
//  Boost Software License, Version 1.0. (See accompanying file
sl@0
     4
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
sl@0
     6
#ifndef BOOST_TR1_UTILITY_HPP_INCLUDED
sl@0
     7
#  define BOOST_TR1_UTILITY_HPP_INCLUDED
sl@0
     8
#  include <boost/tr1/detail/config.hpp>
sl@0
     9
sl@0
    10
#ifdef BOOST_HAS_TR1_UTILITY
sl@0
    11
sl@0
    12
#  ifdef BOOST_HAS_INCLUDE_NEXT
sl@0
    13
#     include_next BOOST_TR1_HEADER(utility)
sl@0
    14
#  else
sl@0
    15
#     include BOOST_TR1_STD_HEADER(BOOST_TR1_PATH(utility))
sl@0
    16
#  endif
sl@0
    17
sl@0
    18
#else
sl@0
    19
sl@0
    20
#if defined(BOOST_TR1_USE_OLD_TUPLE)
sl@0
    21
sl@0
    22
#include <boost/type_traits/integral_constant.hpp>
sl@0
    23
#include <boost/type_traits/add_const.hpp>
sl@0
    24
#include <boost/type_traits/add_reference.hpp>
sl@0
    25
#include <boost/mpl/if.hpp>
sl@0
    26
sl@0
    27
sl@0
    28
namespace std{ namespace tr1{
sl@0
    29
sl@0
    30
template <class T> struct tuple_size; // forward declaration
sl@0
    31
template < int I, class T> struct tuple_element; // forward declaration
sl@0
    32
sl@0
    33
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
    34
template <class T1, class T2>
sl@0
    35
struct tuple_size< ::std::pair<T1, T2> >
sl@0
    36
   : public ::boost::integral_constant< ::std::size_t, 2>
sl@0
    37
{
sl@0
    38
};
sl@0
    39
sl@0
    40
template <class T1, class T2>
sl@0
    41
struct tuple_element<0, ::std::pair<T1, T2> >
sl@0
    42
{
sl@0
    43
   typedef typename std::pair<T1, T2>::first_type type;
sl@0
    44
};
sl@0
    45
sl@0
    46
template <class T1, class T2>
sl@0
    47
struct tuple_element<1, std::pair<T1, T2> >
sl@0
    48
{
sl@0
    49
   typedef typename std::pair<T1, T2>::second_type type;
sl@0
    50
};
sl@0
    51
#endif
sl@0
    52
sl@0
    53
namespace tuple_detail{
sl@0
    54
   template <int I, class T1, class T2>
sl@0
    55
   struct tuple_get_result
sl@0
    56
   {
sl@0
    57
      typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
sl@0
    58
      typedef typename boost::add_reference<t1>::type type;
sl@0
    59
   };
sl@0
    60
   template <int I, class T1, class T2>
sl@0
    61
   struct const_tuple_get_result
sl@0
    62
   {
sl@0
    63
      typedef typename boost::mpl::if_c<I==0, T1, T2>::type t1;
sl@0
    64
# if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x582))
sl@0
    65
      // I have absolutely no idea why add_const is not working here for Borland!
sl@0
    66
      // It passes all other free-standing tests, some strange interaction going on
sl@0
    67
      typedef typename boost::add_reference< const t1 >::type type;
sl@0
    68
# else
sl@0
    69
      typedef typename boost::add_const<t1>::type t2;
sl@0
    70
      typedef typename boost::add_reference<t2>::type type;
sl@0
    71
# endif
sl@0
    72
   };
sl@0
    73
sl@0
    74
template<int I, class T1, class T2>
sl@0
    75
inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::true_type&)
sl@0
    76
{
sl@0
    77
   return p.first;
sl@0
    78
}
sl@0
    79
sl@0
    80
template<int I, class T1, class T2>
sl@0
    81
inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::true_type&)
sl@0
    82
{
sl@0
    83
   return p.first;
sl@0
    84
}
sl@0
    85
sl@0
    86
template<int I, class T1, class T2>
sl@0
    87
inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p, const ::boost::false_type&)
sl@0
    88
{
sl@0
    89
   return p.second;
sl@0
    90
}
sl@0
    91
sl@0
    92
template<int I, class T1, class T2>
sl@0
    93
inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p, const ::boost::false_type&)
sl@0
    94
{
sl@0
    95
   return p.second;
sl@0
    96
}
sl@0
    97
sl@0
    98
}
sl@0
    99
sl@0
   100
template<int I, class T1, class T2> 
sl@0
   101
inline typename tuple_detail::tuple_get_result<I,T1,T2>::type get(std::pair<T1, T2>& p)
sl@0
   102
{
sl@0
   103
   return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
sl@0
   104
}
sl@0
   105
sl@0
   106
template<int I, class T1, class T2> 
sl@0
   107
inline typename tuple_detail::const_tuple_get_result<I,T1,T2>::type get(const std::pair<T1, T2>& p)
sl@0
   108
{
sl@0
   109
   return tuple_detail::get<I>(p, boost::integral_constant<bool, I==0>());
sl@0
   110
}
sl@0
   111
sl@0
   112
} } // namespaces
sl@0
   113
sl@0
   114
#else
sl@0
   115
sl@0
   116
#include <boost/tr1/tuple.hpp>
sl@0
   117
sl@0
   118
#endif
sl@0
   119
sl@0
   120
#endif
sl@0
   121
sl@0
   122
#endif