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 : public integral_constant<std::size_t, 2> { };
93 template<class _Tp1, class _Tp2>
94 struct tuple_element<0, std::pair<_Tp1, _Tp2>>
95 { typedef _Tp1 type; };
97 template<class _Tp1, class _Tp2>
98 struct tuple_element<1, std::pair<_Tp1, _Tp2>>
99 { typedef _Tp2 type; };
101 template<std::size_t _Int>
107 template<typename _Tp1, typename _Tp2>
108 static constexpr _Tp1&
109 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
110 { return __pair.first; }
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); }
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; }
126 template<typename _Tp1, typename _Tp2>
127 static constexpr _Tp2&
128 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
129 { return __pair.second; }
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); }
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; }
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); }
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)); }
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); }
157 _GLIBCXX_END_NAMESPACE_VERSION
162 #endif /* _GLIBCXX_UTILITY */