libstdc++
|
00001 // TR1 utility -*- C++ -*- 00002 00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file tr1_impl/utility 00026 * This is an internal header file, included by other library headers. 00027 * You should not attempt to use it directly. 00028 */ 00029 00030 namespace std 00031 { 00032 _GLIBCXX_BEGIN_NAMESPACE_TR1 00033 00034 template<class _Tp> 00035 class tuple_size; 00036 00037 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00038 template<std::size_t _Int, class _Tp> 00039 #else 00040 template<int _Int, class _Tp> 00041 #endif 00042 class tuple_element; 00043 00044 // Various functions which give std::pair a tuple-like interface. 00045 template<class _Tp1, class _Tp2> 00046 struct tuple_size<std::pair<_Tp1, _Tp2> > 00047 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00048 { static const std::size_t value = 2; }; 00049 #else 00050 { static const int value = 2; }; 00051 #endif 00052 00053 template<class _Tp1, class _Tp2> 00054 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00055 const std::size_t 00056 #else 00057 const int 00058 #endif 00059 tuple_size<std::pair<_Tp1, _Tp2> >::value; 00060 00061 template<class _Tp1, class _Tp2> 00062 struct tuple_element<0, std::pair<_Tp1, _Tp2> > 00063 { typedef _Tp1 type; }; 00064 00065 template<class _Tp1, class _Tp2> 00066 struct tuple_element<1, std::pair<_Tp1, _Tp2> > 00067 { typedef _Tp2 type; }; 00068 00069 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00070 template<std::size_t _Int> 00071 #else 00072 template<int _Int> 00073 #endif 00074 struct __pair_get; 00075 00076 template<> 00077 struct __pair_get<0> 00078 { 00079 template<typename _Tp1, typename _Tp2> 00080 static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) 00081 { return __pair.first; } 00082 00083 template<typename _Tp1, typename _Tp2> 00084 static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 00085 { return __pair.first; } 00086 }; 00087 00088 template<> 00089 struct __pair_get<1> 00090 { 00091 template<typename _Tp1, typename _Tp2> 00092 static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) 00093 { return __pair.second; } 00094 00095 template<typename _Tp1, typename _Tp2> 00096 static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 00097 { return __pair.second; } 00098 }; 00099 00100 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00101 template<std::size_t _Int, class _Tp1, class _Tp2> 00102 #else 00103 template<int _Int, class _Tp1, class _Tp2> 00104 #endif 00105 inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 00106 get(std::pair<_Tp1, _Tp2>& __in) 00107 { return __pair_get<_Int>::__get(__in); } 00108 00109 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X 00110 template<std::size_t _Int, class _Tp1, class _Tp2> 00111 #else 00112 template<int _Int, class _Tp1, class _Tp2> 00113 #endif 00114 inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 00115 get(const std::pair<_Tp1, _Tp2>& __in) 00116 { return __pair_get<_Int>::__const_get(__in); } 00117 00118 _GLIBCXX_END_NAMESPACE_TR1 00119 } 00120