OSDN Git Service

2012-07-06 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     : public integral_constant<std::size_t, 2> { };
92
93   template<class _Tp1, class _Tp2>
94     struct tuple_element<0, std::pair<_Tp1, _Tp2>>
95     { typedef _Tp1 type; };
96  
97   template<class _Tp1, class _Tp2>
98     struct tuple_element<1, std::pair<_Tp1, _Tp2>>
99     { typedef _Tp2 type; };
100
101   template<std::size_t _Int>
102     struct __pair_get;
103
104   template<>
105     struct __pair_get<0>
106     {
107       template<typename _Tp1, typename _Tp2>
108         static constexpr _Tp1&
109         __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
110         { return __pair.first; }
111
112       template<typename _Tp1, typename _Tp2>
113         static constexpr _Tp1&&
114         __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
115         { return std::forward<_Tp1>(__pair.first); }
116
117       template<typename _Tp1, typename _Tp2>
118         static constexpr const _Tp1&
119         __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
120         { return __pair.first; }
121     };
122
123   template<>
124     struct __pair_get<1>
125     {
126       template<typename _Tp1, typename _Tp2>
127         static constexpr _Tp2&
128         __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
129         { return __pair.second; }
130
131       template<typename _Tp1, typename _Tp2>
132         static constexpr _Tp2&&
133         __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
134         { return std::forward<_Tp2>(__pair.second); }
135
136       template<typename _Tp1, typename _Tp2>
137         static constexpr const _Tp2&
138         __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
139         { return __pair.second; }
140     };
141
142   template<std::size_t _Int, class _Tp1, class _Tp2>
143     constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
144     get(std::pair<_Tp1, _Tp2>& __in) noexcept
145     { return __pair_get<_Int>::__get(__in); }
146
147   template<std::size_t _Int, class _Tp1, class _Tp2>
148     constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&&
149     get(std::pair<_Tp1, _Tp2>&& __in) noexcept
150     { return __pair_get<_Int>::__move_get(std::move(__in)); }
151
152   template<std::size_t _Int, class _Tp1, class _Tp2>
153     constexpr const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
154     get(const std::pair<_Tp1, _Tp2>& __in) noexcept
155     { return __pair_get<_Int>::__const_get(__in); }
156
157 _GLIBCXX_END_NAMESPACE_VERSION
158 } // namespace
159
160 #endif
161
162 #endif /* _GLIBCXX_UTILITY */