2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / libstdc++-v3 / include / tr1_impl / utility
blobc70ed9b63cfcc107411d0e4d01535232a29f0b5c
1 // TR1 utility -*- C++ -*-
3 // Copyright (C) 2007, 2008 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 2, 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 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 /** @file tr1_impl/utility
31  *  This is an internal header file, included by other library headers.
32  *  You should not attempt to use it directly.
33  */
35 namespace std
37 _GLIBCXX_BEGIN_NAMESPACE_TR1
39   template<class _Tp>
40     class tuple_size;
42 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
43   template<std::size_t _Int, class _Tp>
44 #else
45   template<int _Int, class _Tp>
46 #endif
47     class tuple_element;
49    // Various functions which give std::pair a tuple-like interface.
50   template<class _Tp1, class _Tp2>
51     struct tuple_size<std::pair<_Tp1, _Tp2> >
52 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
53     { static const std::size_t value = 2; };
54 #else
55     { static const int value = 2; };
56 #endif
58   template<class _Tp1, class _Tp2>
59 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
60     const std::size_t
61 #else
62     const int
63 #endif
64     tuple_size<std::pair<_Tp1, _Tp2> >::value;
66   template<class _Tp1, class _Tp2>
67     struct tuple_element<0, std::pair<_Tp1, _Tp2> >
68     { typedef _Tp1 type; };
70   template<class _Tp1, class _Tp2>
71     struct tuple_element<1, std::pair<_Tp1, _Tp2> >
72     { typedef _Tp2 type; };
74 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
75   template<std::size_t _Int>
76 #else
77   template<int _Int>
78 #endif
79     struct __pair_get;
81   template<>
82     struct __pair_get<0>
83     {
84       template<typename _Tp1, typename _Tp2>
85       static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
86       { return __pair.first; }
88       template<typename _Tp1, typename _Tp2>
89       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
90       { return __pair.first; }
91     };
93   template<>
94     struct __pair_get<1>
95     {
96       template<typename _Tp1, typename _Tp2>
97       static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
98       { return __pair.second; }
100       template<typename _Tp1, typename _Tp2>
101       static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
102       { return __pair.second; }
103     };
105 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
106   template<std::size_t _Int, class _Tp1, class _Tp2>
107 #else
108   template<int _Int, class _Tp1, class _Tp2>
109 #endif
110     inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
111     get(std::pair<_Tp1, _Tp2>& __in)
112     { return __pair_get<_Int>::__get(__in); }
114 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
115   template<std::size_t _Int, class _Tp1, class _Tp2>
116 #else
117   template<int _Int, class _Tp1, class _Tp2>
118 #endif
119     inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
120     get(const std::pair<_Tp1, _Tp2>& __in)
121     { return __pair_get<_Int>::__const_get(__in); }
123 _GLIBCXX_END_NAMESPACE_TR1