1// TR1 utility -*- C++ -*- 2 3// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 2, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING. If not, write to the Free 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19// USA. 20 21// As a special exception, you may use this file as part of a free software 22// library without restriction. Specifically, if other files instantiate 23// templates or use macros or inline functions from this file, or you compile 24// this file and link it with other files to produce an executable, this 25// file does not by itself cause the resulting executable to be covered by 26// the GNU General Public License. This exception does not however 27// invalidate any other reasons why the executable file might be covered by 28// the GNU General Public License. 29 30/** @file tr1/utility 31 * This is a TR1 C++ Library header. 32 */ 33 34#ifndef _TR1_UTILITY 35#define _TR1_UTILITY 1 36 37#include "../utility" 38 39namespace std 40{ 41_GLIBCXX_BEGIN_NAMESPACE(tr1) 42 43 template<class _Tp> class tuple_size; 44 template<int _Int, class _Tp> class tuple_element; 45 46 // Various functions which give std::pair a tuple-like interface. 47 template<class _Tp1, class _Tp2> 48 struct tuple_size<std::pair<_Tp1, _Tp2> > 49 { static const int value = 2; }; 50 51 template<class _Tp1, class _Tp2> 52 const int tuple_size<std::pair<_Tp1, _Tp2> >::value; 53 54 template<class _Tp1, class _Tp2> 55 struct tuple_element<0, std::pair<_Tp1, _Tp2> > 56 { typedef _Tp1 type; }; 57 58 template<class _Tp1, class _Tp2> 59 struct tuple_element<1, std::pair<_Tp1, _Tp2> > 60 { typedef _Tp2 type; }; 61 62 63 template<int _Int> struct __pair_get; 64 65 template<> 66 struct __pair_get<0> 67 { 68 template<typename _Tp1, typename _Tp2> 69 static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) 70 { return __pair.first; } 71 72 template<typename _Tp1, typename _Tp2> 73 static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 74 { return __pair.first; } 75 }; 76 77 template<> 78 struct __pair_get<1> 79 { 80 template<typename _Tp1, typename _Tp2> 81 static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) 82 { return __pair.second; } 83 84 template<typename _Tp1, typename _Tp2> 85 static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 86 { return __pair.second; } 87 }; 88 89 template<int _Int, class _Tp1, class _Tp2> 90 inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 91 get(std::pair<_Tp1, _Tp2>& __in) 92 { return __pair_get<_Int>::__get(__in); } 93 94 template<int _Int, class _Tp1, class _Tp2> 95 inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 96 get(const std::pair<_Tp1, _Tp2>& __in) 97 { return __pair_get<_Int>::__const_get(__in); } 98 99_GLIBCXX_END_NAMESPACE 100} 101 102#endif 103