1 // <utility> -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
5 // Free Software Foundation, Inc.
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)
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.
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.
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/>.
30 * Hewlett-Packard Company
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.
41 * Copyright (c) 1996,1997
42 * Silicon Graphics Computer Systems, Inc.
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.
53 /** @file include/utility
54 * This is a Standard C++ Library header.
57 #ifndef _GLIBCXX_UTILITY
58 #define _GLIBCXX_UTILITY 1
60 #pragma GCC system_header
63 * @defgroup utilities Utilities
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.
70 #include <bits/c++config.h>
71 #include <bits/stl_relops.h>
72 #include <bits/stl_pair.h>
74 #ifdef __GXX_EXPERIMENTAL_CXX0X__
75 #include <bits/move.h>
76 #include <initializer_list>
78 namespace std _GLIBCXX_VISIBILITY(default)
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
85 template<std::size_t _Int, class _Tp>
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; };
93 template<class _Tp1, class _Tp2>
95 tuple_size<std::pair<_Tp1, _Tp2> >::value;
97 template<class _Tp1, class _Tp2>
98 struct tuple_element<0, std::pair<_Tp1, _Tp2>>
99 { typedef _Tp1 type; };
101 template<class _Tp1, class _Tp2>
102 struct tuple_element<1, std::pair<_Tp1, _Tp2>>
103 { typedef _Tp2 type; };
105 template<std::size_t _Int>
111 template<typename _Tp1, typename _Tp2>
113 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
114 { return __pair.first; }
116 template<typename _Tp1, typename _Tp2>
118 __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
119 { return std::forward<_Tp1>(__pair.first); }
121 template<typename _Tp1, typename _Tp2>
123 __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
124 { return __pair.first; }
130 template<typename _Tp1, typename _Tp2>
132 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
133 { return __pair.second; }
135 template<typename _Tp1, typename _Tp2>
137 __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
138 { return std::forward<_Tp2>(__pair.second); }
140 template<typename _Tp1, typename _Tp2>
142 __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
143 { return __pair.second; }
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); }
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)); }
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); }
161 _GLIBCXX_END_NAMESPACE_VERSION
166 #endif /* _GLIBCXX_UTILITY */