OSDN Git Service

2011-05-16 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / utility
1 // <utility> -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 // 2010, 2011
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
21
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25 // <http://www.gnu.org/licenses/>.
26
27 /*
28  *
29  * Copyright (c) 1994
30  * Hewlett-Packard Company
31  *
32  * Permission to use, copy, modify, distribute and sell this software
33  * and its documentation for any purpose is hereby granted without fee,
34  * provided that the above copyright notice appear in all copies and
35  * that both that copyright notice and this permission notice appear
36  * in supporting documentation.  Hewlett-Packard Company makes no
37  * representations about the suitability of this software for any
38  * purpose.  It is provided "as is" without express or implied warranty.
39  *
40  *
41  * Copyright (c) 1996,1997
42  * Silicon Graphics Computer Systems, Inc.
43  *
44  * Permission to use, copy, modify, distribute and sell this software
45  * and its documentation for any purpose is hereby granted without fee,
46  * provided that the above copyright notice appear in all copies and
47  * that both that copyright notice and this permission notice appear
48  * in supporting documentation.  Silicon Graphics makes no
49  * representations about the suitability of this software for any
50  * purpose.  It is provided "as is" without express or implied warranty.
51  */
52
53 /** @file include/utility
54  *  This is a Standard C++ Library header. 
55  */
56
57 #ifndef _GLIBCXX_UTILITY
58 #define _GLIBCXX_UTILITY 1
59
60 #pragma GCC system_header
61
62 /**
63  * @defgroup utilities Utilities
64  *
65  * Components deemed generally useful. Includes pair, tuple,
66  * forward/move helpers, ratio, function object, metaprogramming and
67  * type traits, time, date, and memory functions.
68  */
69
70 #include <bits/c++config.h>
71 #include <bits/stl_relops.h>
72 #include <bits/stl_pair.h>
73
74 #ifdef __GXX_EXPERIMENTAL_CXX0X__
75 #include <bits/move.h>
76 #include <initializer_list>
77
78 namespace std _GLIBCXX_VISIBILITY(default)
79 {
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
81
82   template<class _Tp>
83     class tuple_size;
84
85   template<std::size_t _Int, class _Tp>
86     class tuple_element;
87
88    // Various functions which give std::pair a tuple-like interface.
89   template<class _Tp1, class _Tp2>
90     struct tuple_size<std::pair<_Tp1, _Tp2>>
91     { static const std::size_t value = 2; };
92
93   template<class _Tp1, class _Tp2>
94     const std::size_t
95     tuple_size<std::pair<_Tp1, _Tp2> >::value;
96
97   template<class _Tp1, class _Tp2>
98     struct tuple_element<0, std::pair<_Tp1, _Tp2>>
99     { typedef _Tp1 type; };
100  
101   template<class _Tp1, class _Tp2>
102     struct tuple_element<1, std::pair<_Tp1, _Tp2>>
103     { typedef _Tp2 type; };
104
105   template<std::size_t _Int>
106     struct __pair_get;
107
108   template<>
109     struct __pair_get<0>
110     {
111       template<typename _Tp1, typename _Tp2>
112         static _Tp1&
113         __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
114         { return __pair.first; }
115
116       template<typename _Tp1, typename _Tp2>
117         static _Tp1&&
118         __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
119         { return std::forward<_Tp1>(__pair.first); }
120
121       template<typename _Tp1, typename _Tp2>
122         static const _Tp1&
123         __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
124         { return __pair.first; }
125     };
126
127   template<>
128     struct __pair_get<1>
129     {
130       template<typename _Tp1, typename _Tp2>
131         static _Tp2&
132         __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
133         { return __pair.second; }
134
135       template<typename _Tp1, typename _Tp2>
136         static _Tp2&&
137         __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
138         { return std::forward<_Tp2>(__pair.second); }
139
140       template<typename _Tp1, typename _Tp2>
141         static const _Tp2&
142         __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
143         { return __pair.second; }
144     };
145
146   template<std::size_t _Int, class _Tp1, class _Tp2>
147     inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
148     get(std::pair<_Tp1, _Tp2>& __in) noexcept
149     { return __pair_get<_Int>::__get(__in); }
150
151   template<std::size_t _Int, class _Tp1, class _Tp2>
152     inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&&
153     get(std::pair<_Tp1, _Tp2>&& __in) noexcept
154     { return __pair_get<_Int>::__move_get(std::move(__in)); }
155
156   template<std::size_t _Int, class _Tp1, class _Tp2>
157     inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
158     get(const std::pair<_Tp1, _Tp2>& __in) noexcept
159     { return __pair_get<_Int>::__const_get(__in); }
160
161 _GLIBCXX_END_NAMESPACE_VERSION
162 } // namespace
163
164 #endif
165
166 #endif /* _GLIBCXX_UTILITY */