Home | History | Annotate | Download | only in tr1
      1 // TR1 utility -*- C++ -*-
      2 
      3 // Copyright (C) 2004, 2005, 2006, 2007, 2008. 2009, 2010, 2011
      4 // Free Software Foundation, Inc.
      5 //
      6 // This file is part of the GNU ISO C++ Library.  This library is free
      7 // software; you can redistribute it and/or modify it under the
      8 // terms of the GNU General Public License as published by the
      9 // Free Software Foundation; either version 3, or (at your option)
     10 // any later version.
     11 
     12 // This library is distributed in the hope that it will be useful,
     13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 // GNU General Public License for more details.
     16 
     17 // Under Section 7 of GPL version 3, you are granted additional
     18 // permissions described in the GCC Runtime Library Exception, version
     19 // 3.1, as published by the Free Software Foundation.
     20 
     21 // You should have received a copy of the GNU General Public License and
     22 // a copy of the GCC Runtime Library Exception along with this program;
     23 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     24 // <http://www.gnu.org/licenses/>.
     25 
     26 /** @file tr1/utility
     27  *  This is a TR1 C++ Library header. 
     28  */
     29 
     30 #ifndef _GLIBCXX_TR1_UTILITY
     31 #define _GLIBCXX_TR1_UTILITY 1
     32 
     33 #pragma GCC system_header
     34 
     35 #include <bits/c++config.h>
     36 #include <bits/stl_relops.h>
     37 #include <bits/stl_pair.h>
     38 
     39 namespace std _GLIBCXX_VISIBILITY(default)
     40 {
     41 namespace tr1
     42 {
     43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
     44 
     45   template<class _Tp>
     46     class tuple_size;
     47 
     48   template<int _Int, class _Tp>
     49     class tuple_element;
     50 
     51    // Various functions which give std::pair a tuple-like interface.
     52   template<class _Tp1, class _Tp2>
     53     struct tuple_size<std::pair<_Tp1, _Tp2> >
     54     { static const int value = 2; };
     55 
     56   template<class _Tp1, class _Tp2>
     57     const int
     58     tuple_size<std::pair<_Tp1, _Tp2> >::value;
     59 
     60   template<class _Tp1, class _Tp2>
     61     struct tuple_element<0, std::pair<_Tp1, _Tp2> >
     62     { typedef _Tp1 type; };
     63  
     64   template<class _Tp1, class _Tp2>
     65     struct tuple_element<1, std::pair<_Tp1, _Tp2> >
     66     { typedef _Tp2 type; };
     67 
     68   template<int _Int>
     69     struct __pair_get;
     70 
     71   template<>
     72     struct __pair_get<0>
     73     {
     74       template<typename _Tp1, typename _Tp2>
     75       static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
     76       { return __pair.first; }
     77 
     78       template<typename _Tp1, typename _Tp2>
     79       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
     80       { return __pair.first; }
     81     };
     82 
     83   template<>
     84     struct __pair_get<1>
     85     {
     86       template<typename _Tp1, typename _Tp2>
     87       static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
     88       { return __pair.second; }
     89 
     90       template<typename _Tp1, typename _Tp2>
     91       static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
     92       { return __pair.second; }
     93     };
     94 
     95   template<int _Int, class _Tp1, class _Tp2>
     96     inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
     97     get(std::pair<_Tp1, _Tp2>& __in)
     98     { return __pair_get<_Int>::__get(__in); }
     99 
    100   template<int _Int, class _Tp1, class _Tp2>
    101     inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
    102     get(const std::pair<_Tp1, _Tp2>& __in)
    103     { return __pair_get<_Int>::__const_get(__in); }
    104 
    105 _GLIBCXX_END_NAMESPACE_VERSION
    106 }
    107 }
    108 
    109 #endif // _GLIBCXX_TR1_UTILITY
    110