1 // <utility> -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
29 * Hewlett-Packard Company
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
40 * Copyright (c) 1996,1997
41 * Silicon Graphics Computer Systems, Inc.
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
52 /** @file include/utility
53 * This is a Standard C++ Library header.
56 #ifndef _GLIBCXX_UTILITY
57 #define _GLIBCXX_UTILITY 1
59 #pragma GCC system_header
62 * @defgroup utilities Utilities
64 * Components deemed generally useful. Includes pair, tuple,
65 * forward/move helpers, ratio, function object, metaprogramming and
66 * type traits, time, date, and memory functions.
69 #include <bits/c++config.h>
70 #include <bits/stl_relops.h>
71 #include <bits/stl_pair.h>
73 #ifdef __GXX_EXPERIMENTAL_CXX0X__
74 #include <bits/move.h>
75 #include <initializer_list>
77 namespace std _GLIBCXX_VISIBILITY(default)
79 _GLIBCXX_BEGIN_NAMESPACE_VERSION
84 template<std::size_t _Int, class _Tp>
87 // Various functions which give std::pair a tuple-like interface.
88 template<class _Tp1, class _Tp2>
89 struct tuple_size<std::pair<_Tp1, _Tp2> >
90 { static const std::size_t value = 2; };
92 template<class _Tp1, class _Tp2>
94 tuple_size<std::pair<_Tp1, _Tp2> >::value;
96 template<class _Tp1, class _Tp2>
97 struct tuple_element<0, std::pair<_Tp1, _Tp2> >
98 { typedef _Tp1 type; };
100 template<class _Tp1, class _Tp2>
101 struct tuple_element<1, std::pair<_Tp1, _Tp2> >
102 { typedef _Tp2 type; };
104 template<std::size_t _Int>
110 template<typename _Tp1, typename _Tp2>
111 static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
112 { return __pair.first; }
114 template<typename _Tp1, typename _Tp2>
115 static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
116 { return __pair.first; }
122 template<typename _Tp1, typename _Tp2>
123 static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
124 { return __pair.second; }
126 template<typename _Tp1, typename _Tp2>
127 static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
128 { return __pair.second; }
131 template<std::size_t _Int, class _Tp1, class _Tp2>
132 inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
133 get(std::pair<_Tp1, _Tp2>& __in)
134 { return __pair_get<_Int>::__get(__in); }
136 template<std::size_t _Int, class _Tp1, class _Tp2>
137 inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
138 get(const std::pair<_Tp1, _Tp2>& __in)
139 { return __pair_get<_Int>::__const_get(__in); }
141 _GLIBCXX_END_NAMESPACE_VERSION
146 #endif /* _GLIBCXX_UTILITY */