libstdc++
utility
Go to the documentation of this file.
1 // <utility> -*- C++ -*-
2 
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
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)
10 // any later version.
11 
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.
16 
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.
20 
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/>.
25 
26 /*
27  *
28  * Copyright (c) 1994
29  * Hewlett-Packard Company
30  *
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.
38  *
39  *
40  * Copyright (c) 1996,1997
41  * Silicon Graphics Computer Systems, Inc.
42  *
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.
50  */
51 
52 /** @file include/utility
53  * This is a Standard C++ Library header.
54  */
55 
56 #ifndef _GLIBCXX_UTILITY
57 #define _GLIBCXX_UTILITY 1
58 
59 #pragma GCC system_header
60 
61 /**
62  * @defgroup utilities Utilities
63  *
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.
67  */
68 
69 #include <bits/c++config.h>
70 #include <bits/stl_relops.h>
71 #include <bits/stl_pair.h>
72 
73 #ifdef __GXX_EXPERIMENTAL_CXX0X__
74 #include <bits/move.h>
75 #include <initializer_list>
76 
77 namespace std _GLIBCXX_VISIBILITY(default)
78 {
79 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 
81  template<class _Tp>
82  class tuple_size;
83 
84  template<std::size_t _Int, class _Tp>
85  class tuple_element;
86 
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; };
91 
92  template<class _Tp1, class _Tp2>
93  const std::size_t
94  tuple_size<std::pair<_Tp1, _Tp2> >::value;
95 
96  template<class _Tp1, class _Tp2>
97  struct tuple_element<0, std::pair<_Tp1, _Tp2> >
98  { typedef _Tp1 type; };
99 
100  template<class _Tp1, class _Tp2>
101  struct tuple_element<1, std::pair<_Tp1, _Tp2> >
102  { typedef _Tp2 type; };
103 
104  template<std::size_t _Int>
105  struct __pair_get;
106 
107  template<>
108  struct __pair_get<0>
109  {
110  template<typename _Tp1, typename _Tp2>
111  static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
112  { return __pair.first; }
113 
114  template<typename _Tp1, typename _Tp2>
115  static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
116  { return __pair.first; }
117  };
118 
119  template<>
120  struct __pair_get<1>
121  {
122  template<typename _Tp1, typename _Tp2>
123  static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
124  { return __pair.second; }
125 
126  template<typename _Tp1, typename _Tp2>
127  static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
128  { return __pair.second; }
129  };
130 
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); }
135 
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); }
140 
141 _GLIBCXX_END_NAMESPACE_VERSION
142 } // namespace
143 
144 #endif
145 
146 #endif /* _GLIBCXX_UTILITY */
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:87
_T1 first
second_type is the second bound type
Definition: stl_pair.h:92
_T2 second
first is a copy of the first object
Definition: stl_pair.h:93