libstdc++
|
00001 // <utility> -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 00004 // 2010, 2011 00005 // Free Software Foundation, Inc. 00006 // 00007 // This file is part of the GNU ISO C++ Library. This library is free 00008 // software; you can redistribute it and/or modify it under the 00009 // terms of the GNU General Public License as published by the 00010 // Free Software Foundation; either version 3, or (at your option) 00011 // any later version. 00012 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 00018 // Under Section 7 of GPL version 3, you are granted additional 00019 // permissions described in the GCC Runtime Library Exception, version 00020 // 3.1, as published by the Free Software Foundation. 00021 00022 // You should have received a copy of the GNU General Public License and 00023 // a copy of the GCC Runtime Library Exception along with this program; 00024 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00025 // <http://www.gnu.org/licenses/>. 00026 00027 /* 00028 * 00029 * Copyright (c) 1994 00030 * Hewlett-Packard Company 00031 * 00032 * Permission to use, copy, modify, distribute and sell this software 00033 * and its documentation for any purpose is hereby granted without fee, 00034 * provided that the above copyright notice appear in all copies and 00035 * that both that copyright notice and this permission notice appear 00036 * in supporting documentation. Hewlett-Packard Company makes no 00037 * representations about the suitability of this software for any 00038 * purpose. It is provided "as is" without express or implied warranty. 00039 * 00040 * 00041 * Copyright (c) 1996,1997 00042 * Silicon Graphics Computer Systems, Inc. 00043 * 00044 * Permission to use, copy, modify, distribute and sell this software 00045 * and its documentation for any purpose is hereby granted without fee, 00046 * provided that the above copyright notice appear in all copies and 00047 * that both that copyright notice and this permission notice appear 00048 * in supporting documentation. Silicon Graphics makes no 00049 * representations about the suitability of this software for any 00050 * purpose. It is provided "as is" without express or implied warranty. 00051 */ 00052 00053 /** @file include/utility 00054 * This is a Standard C++ Library header. 00055 */ 00056 00057 #ifndef _GLIBCXX_UTILITY 00058 #define _GLIBCXX_UTILITY 1 00059 00060 #pragma GCC system_header 00061 00062 /** 00063 * @defgroup utilities Utilities 00064 * 00065 * Components deemed generally useful. Includes pair, tuple, 00066 * forward/move helpers, ratio, function object, metaprogramming and 00067 * type traits, time, date, and memory functions. 00068 */ 00069 00070 #include <bits/c++config.h> 00071 #include <bits/stl_relops.h> 00072 #include <bits/stl_pair.h> 00073 00074 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00075 #include <bits/move.h> 00076 #include <initializer_list> 00077 00078 namespace std _GLIBCXX_VISIBILITY(default) 00079 { 00080 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00081 00082 template<class _Tp> 00083 class tuple_size; 00084 00085 template<std::size_t _Int, class _Tp> 00086 class tuple_element; 00087 00088 // Various functions which give std::pair a tuple-like interface. 00089 template<class _Tp1, class _Tp2> 00090 struct tuple_size<std::pair<_Tp1, _Tp2>> 00091 : public integral_constant<std::size_t, 2> { }; 00092 00093 template<class _Tp1, class _Tp2> 00094 struct tuple_element<0, std::pair<_Tp1, _Tp2>> 00095 { typedef _Tp1 type; }; 00096 00097 template<class _Tp1, class _Tp2> 00098 struct tuple_element<1, std::pair<_Tp1, _Tp2>> 00099 { typedef _Tp2 type; }; 00100 00101 template<std::size_t _Int> 00102 struct __pair_get; 00103 00104 template<> 00105 struct __pair_get<0> 00106 { 00107 template<typename _Tp1, typename _Tp2> 00108 static constexpr _Tp1& 00109 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept 00110 { return __pair.first; } 00111 00112 template<typename _Tp1, typename _Tp2> 00113 static constexpr _Tp1&& 00114 __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept 00115 { return std::forward<_Tp1>(__pair.first); } 00116 00117 template<typename _Tp1, typename _Tp2> 00118 static constexpr const _Tp1& 00119 __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept 00120 { return __pair.first; } 00121 }; 00122 00123 template<> 00124 struct __pair_get<1> 00125 { 00126 template<typename _Tp1, typename _Tp2> 00127 static constexpr _Tp2& 00128 __get(std::pair<_Tp1, _Tp2>& __pair) noexcept 00129 { return __pair.second; } 00130 00131 template<typename _Tp1, typename _Tp2> 00132 static constexpr _Tp2&& 00133 __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept 00134 { return std::forward<_Tp2>(__pair.second); } 00135 00136 template<typename _Tp1, typename _Tp2> 00137 static constexpr const _Tp2& 00138 __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept 00139 { return __pair.second; } 00140 }; 00141 00142 template<std::size_t _Int, class _Tp1, class _Tp2> 00143 constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& 00144 get(std::pair<_Tp1, _Tp2>& __in) noexcept 00145 { return __pair_get<_Int>::__get(__in); } 00146 00147 template<std::size_t _Int, class _Tp1, class _Tp2> 00148 constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&& 00149 get(std::pair<_Tp1, _Tp2>&& __in) noexcept 00150 { return __pair_get<_Int>::__move_get(std::move(__in)); } 00151 00152 template<std::size_t _Int, class _Tp1, class _Tp2> 00153 constexpr const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& 00154 get(const std::pair<_Tp1, _Tp2>& __in) noexcept 00155 { return __pair_get<_Int>::__const_get(__in); } 00156 00157 _GLIBCXX_END_NAMESPACE_VERSION 00158 } // namespace 00159 00160 #endif 00161 00162 #endif /* _GLIBCXX_UTILITY */