1169691Skan// TR1 utility -*- C++ -*- 2169691Skan 3169691Skan// Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. 4169691Skan// 5169691Skan// This file is part of the GNU ISO C++ Library. This library is free 6169691Skan// software; you can redistribute it and/or modify it under the 7169691Skan// terms of the GNU General Public License as published by the 8169691Skan// Free Software Foundation; either version 2, or (at your option) 9169691Skan// any later version. 10169691Skan 11169691Skan// This library is distributed in the hope that it will be useful, 12169691Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169691Skan// GNU General Public License for more details. 15169691Skan 16169691Skan// You should have received a copy of the GNU General Public License along 17169691Skan// with this library; see the file COPYING. If not, write to the Free 18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 19169691Skan// USA. 20169691Skan 21169691Skan// As a special exception, you may use this file as part of a free software 22169691Skan// library without restriction. Specifically, if other files instantiate 23169691Skan// templates or use macros or inline functions from this file, or you compile 24169691Skan// this file and link it with other files to produce an executable, this 25169691Skan// file does not by itself cause the resulting executable to be covered by 26169691Skan// the GNU General Public License. This exception does not however 27169691Skan// invalidate any other reasons why the executable file might be covered by 28169691Skan// the GNU General Public License. 29169691Skan 30169691Skan/** @file tr1/utility 31169691Skan * This is a TR1 C++ Library header. 32169691Skan */ 33169691Skan 34169691Skan#ifndef _TR1_UTILITY 35169691Skan#define _TR1_UTILITY 1 36169691Skan 37169691Skan#include "../utility" 38169691Skan 39169691Skannamespace std 40169691Skan{ 41169691Skan_GLIBCXX_BEGIN_NAMESPACE(tr1) 42169691Skan 43169691Skan template<class _Tp> class tuple_size; 44169691Skan template<int _Int, class _Tp> class tuple_element; 45169691Skan 46169691Skan // Various functions which give std::pair a tuple-like interface. 47169691Skan template<class _Tp1, class _Tp2> 48169691Skan struct tuple_size<std::pair<_Tp1, _Tp2> > 49169691Skan { static const int value = 2; }; 50169691Skan 51169691Skan template<class _Tp1, class _Tp2> 52169691Skan const int tuple_size<std::pair<_Tp1, _Tp2> >::value; 53169691Skan 54169691Skan template<class _Tp1, class _Tp2> 55169691Skan struct tuple_element<0, std::pair<_Tp1, _Tp2> > 56169691Skan { typedef _Tp1 type; }; 57169691Skan 58169691Skan template<class _Tp1, class _Tp2> 59169691Skan struct tuple_element<1, std::pair<_Tp1, _Tp2> > 60169691Skan { typedef _Tp2 type; }; 61169691Skan 62169691Skan 63169691Skan template<int _Int> struct __pair_get; 64169691Skan 65169691Skan template<> 66169691Skan struct __pair_get<0> 67169691Skan { 68169691Skan template<typename _Tp1, typename _Tp2> 69169691Skan static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair) 70169691Skan { return __pair.first; } 71169691Skan 72169691Skan template<typename _Tp1, typename _Tp2> 73169691Skan static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 74169691Skan { return __pair.first; } 75169691Skan }; 76169691Skan 77169691Skan template<> 78169691Skan struct __pair_get<1> 79169691Skan { 80169691Skan template<typename _Tp1, typename _Tp2> 81169691Skan static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair) 82169691Skan { return __pair.second; } 83169691Skan 84169691Skan template<typename _Tp1, typename _Tp2> 85169691Skan static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair) 86169691Skan { return __pair.second; } 87169691Skan }; 88169691Skan 89169691Skan template<int _Int, class _Tp1, class _Tp2> 90169691Skan inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 91169691Skan get(std::pair<_Tp1, _Tp2>& __in) 92169691Skan { return __pair_get<_Int>::__get(__in); } 93169691Skan 94169691Skan template<int _Int, class _Tp1, class _Tp2> 95169691Skan inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& 96169691Skan get(const std::pair<_Tp1, _Tp2>& __in) 97169691Skan { return __pair_get<_Int>::__const_get(__in); } 98169691Skan 99169691Skan_GLIBCXX_END_NAMESPACE 100169691Skan} 101169691Skan 102169691Skan#endif 103