2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / libstdc++-v3 / include / tr1_impl / utility
blobc3b3527f96353ffbbdcd5f644275dbed6499b876
1 // TR1 utility -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
25 /** @file tr1_impl/utility
26  *  This is an internal header file, included by other library headers.
27  *  You should not attempt to use it directly.
28  */
30 namespace std
32 _GLIBCXX_BEGIN_NAMESPACE_TR1
34   template<class _Tp>
35     class tuple_size;
37 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
38   template<std::size_t _Int, class _Tp>
39 #else
40   template<int _Int, class _Tp>
41 #endif
42     class tuple_element;
44    // Various functions which give std::pair a tuple-like interface.
45   template<class _Tp1, class _Tp2>
46     struct tuple_size<std::pair<_Tp1, _Tp2> >
47 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
48     { static const std::size_t value = 2; };
49 #else
50     { static const int value = 2; };
51 #endif
53   template<class _Tp1, class _Tp2>
54 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
55     const std::size_t
56 #else
57     const int
58 #endif
59     tuple_size<std::pair<_Tp1, _Tp2> >::value;
61   template<class _Tp1, class _Tp2>
62     struct tuple_element<0, std::pair<_Tp1, _Tp2> >
63     { typedef _Tp1 type; };
65   template<class _Tp1, class _Tp2>
66     struct tuple_element<1, std::pair<_Tp1, _Tp2> >
67     { typedef _Tp2 type; };
69 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
70   template<std::size_t _Int>
71 #else
72   template<int _Int>
73 #endif
74     struct __pair_get;
76   template<>
77     struct __pair_get<0>
78     {
79       template<typename _Tp1, typename _Tp2>
80       static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
81       { return __pair.first; }
83       template<typename _Tp1, typename _Tp2>
84       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
85       { return __pair.first; }
86     };
88   template<>
89     struct __pair_get<1>
90     {
91       template<typename _Tp1, typename _Tp2>
92       static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
93       { return __pair.second; }
95       template<typename _Tp1, typename _Tp2>
96       static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
97       { return __pair.second; }
98     };
100 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
101   template<std::size_t _Int, class _Tp1, class _Tp2>
102 #else
103   template<int _Int, class _Tp1, class _Tp2>
104 #endif
105     inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
106     get(std::pair<_Tp1, _Tp2>& __in)
107     { return __pair_get<_Int>::__get(__in); }
109 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
110   template<std::size_t _Int, class _Tp1, class _Tp2>
111 #else
112   template<int _Int, class _Tp1, class _Tp2>
113 #endif
114     inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
115     get(const std::pair<_Tp1, _Tp2>& __in)
116     { return __pair_get<_Int>::__const_get(__in); }
118 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
119   /**
120    *  @brief  Return the first of a pair containing two input iterators.
121    *  @param  p  Pair.
122    */
123   template<class _InputIterator>
124     inline _InputIterator
125     begin(const std::pair<_InputIterator, _InputIterator>& __p)
126     { return __p.first; }
128   /**
129    *  @brief  Return the second of a pair containing two input iterators.
130    *  @param  p  Pair.
131    */
132   template<class _InputIterator>
133     inline _InputIterator
134     end(const std::pair<_InputIterator, _InputIterator>& __p)
135     { return __p.second; }
136 #endif
138 _GLIBCXX_END_NAMESPACE_TR1