1*e4b17023SJohn Marino// <utility> -*- C++ -*- 2*e4b17023SJohn Marino 3*e4b17023SJohn Marino// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4*e4b17023SJohn Marino// 2010, 2011 5*e4b17023SJohn Marino// Free Software Foundation, Inc. 6*e4b17023SJohn Marino// 7*e4b17023SJohn Marino// This file is part of the GNU ISO C++ Library. This library is free 8*e4b17023SJohn Marino// software; you can redistribute it and/or modify it under the 9*e4b17023SJohn Marino// terms of the GNU General Public License as published by the 10*e4b17023SJohn Marino// Free Software Foundation; either version 3, or (at your option) 11*e4b17023SJohn Marino// any later version. 12*e4b17023SJohn Marino 13*e4b17023SJohn Marino// This library is distributed in the hope that it will be useful, 14*e4b17023SJohn Marino// but WITHOUT ANY WARRANTY; without even the implied warranty of 15*e4b17023SJohn Marino// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*e4b17023SJohn Marino// GNU General Public License for more details. 17*e4b17023SJohn Marino 18*e4b17023SJohn Marino// Under Section 7 of GPL version 3, you are granted additional 19*e4b17023SJohn Marino// permissions described in the GCC Runtime Library Exception, version 20*e4b17023SJohn Marino// 3.1, as published by the Free Software Foundation. 21*e4b17023SJohn Marino 22*e4b17023SJohn Marino// You should have received a copy of the GNU General Public License and 23*e4b17023SJohn Marino// a copy of the GCC Runtime Library Exception along with this program; 24*e4b17023SJohn Marino// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 25*e4b17023SJohn Marino// <http://www.gnu.org/licenses/>. 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino/* 28*e4b17023SJohn Marino * 29*e4b17023SJohn Marino * Copyright (c) 1994 30*e4b17023SJohn Marino * Hewlett-Packard Company 31*e4b17023SJohn Marino * 32*e4b17023SJohn Marino * Permission to use, copy, modify, distribute and sell this software 33*e4b17023SJohn Marino * and its documentation for any purpose is hereby granted without fee, 34*e4b17023SJohn Marino * provided that the above copyright notice appear in all copies and 35*e4b17023SJohn Marino * that both that copyright notice and this permission notice appear 36*e4b17023SJohn Marino * in supporting documentation. Hewlett-Packard Company makes no 37*e4b17023SJohn Marino * representations about the suitability of this software for any 38*e4b17023SJohn Marino * purpose. It is provided "as is" without express or implied warranty. 39*e4b17023SJohn Marino * 40*e4b17023SJohn Marino * 41*e4b17023SJohn Marino * Copyright (c) 1996,1997 42*e4b17023SJohn Marino * Silicon Graphics Computer Systems, Inc. 43*e4b17023SJohn Marino * 44*e4b17023SJohn Marino * Permission to use, copy, modify, distribute and sell this software 45*e4b17023SJohn Marino * and its documentation for any purpose is hereby granted without fee, 46*e4b17023SJohn Marino * provided that the above copyright notice appear in all copies and 47*e4b17023SJohn Marino * that both that copyright notice and this permission notice appear 48*e4b17023SJohn Marino * in supporting documentation. Silicon Graphics makes no 49*e4b17023SJohn Marino * representations about the suitability of this software for any 50*e4b17023SJohn Marino * purpose. It is provided "as is" without express or implied warranty. 51*e4b17023SJohn Marino */ 52*e4b17023SJohn Marino 53*e4b17023SJohn Marino/** @file include/utility 54*e4b17023SJohn Marino * This is a Standard C++ Library header. 55*e4b17023SJohn Marino */ 56*e4b17023SJohn Marino 57*e4b17023SJohn Marino#ifndef _GLIBCXX_UTILITY 58*e4b17023SJohn Marino#define _GLIBCXX_UTILITY 1 59*e4b17023SJohn Marino 60*e4b17023SJohn Marino#pragma GCC system_header 61*e4b17023SJohn Marino 62*e4b17023SJohn Marino/** 63*e4b17023SJohn Marino * @defgroup utilities Utilities 64*e4b17023SJohn Marino * 65*e4b17023SJohn Marino * Components deemed generally useful. Includes pair, tuple, 66*e4b17023SJohn Marino * forward/move helpers, ratio, function object, metaprogramming and 67*e4b17023SJohn Marino * type traits, time, date, and memory functions. 68*e4b17023SJohn Marino */ 69*e4b17023SJohn Marino 70*e4b17023SJohn Marino#include <bits/c++config.h> 71*e4b17023SJohn Marino#include <bits/stl_relops.h> 72*e4b17023SJohn Marino#include <bits/stl_pair.h> 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino#ifdef __GXX_EXPERIMENTAL_CXX0X__ 75*e4b17023SJohn Marino#include <bits/move.h> 76*e4b17023SJohn Marino#include <initializer_list> 77*e4b17023SJohn Marino 78*e4b17023SJohn Marinonamespace std _GLIBCXX_VISIBILITY(default) 79*e4b17023SJohn Marino{ 80*e4b17023SJohn Marino_GLIBCXX_BEGIN_NAMESPACE_VERSION 81*e4b17023SJohn Marino 82*e4b17023SJohn Marino template<class _Tp> 83*e4b17023SJohn Marino class tuple_size; 84*e4b17023SJohn Marino 85*e4b17023SJohn Marino template<std::size_t _Int, class _Tp> 86*e4b17023SJohn Marino class tuple_element; 87*e4b17023SJohn Marino 88*e4b17023SJohn Marino // Various functions which give std::pair a tuple-like interface. 89*e4b17023SJohn Marino template<class _Tp1, class _Tp2> 90*e4b17023SJohn Marino struct tuple_size<std::pair<_Tp1, _Tp2>> 91*e4b17023SJohn Marino : public integral_constant<std::size_t, 2> { }; 92*e4b17023SJohn Marino 93*e4b17023SJohn Marino template<class _Tp1, class _Tp2> 94*e4b17023SJohn Marino struct tuple_element<0, std::pair<_Tp1, _Tp2>> 95*e4b17023SJohn Marino { typedef _Tp1 type; }; 96*e4b17023SJohn Marino 97*e4b17023SJohn Marino template<class _Tp1, class _Tp2> 98*e4b17023SJohn Marino struct tuple_element<1, std::pair<_Tp1, _Tp2>> 99*e4b17023SJohn Marino { typedef _Tp2 type; }; 100*e4b17023SJohn Marino 101*e4b17023SJohn Marino template<std::size_t _Int> 102*e4b17023SJohn Marino struct __pair_get; 103*e4b17023SJohn Marino 104*e4b17023SJohn Marino template<> 105*e4b17023SJohn Marino struct __pair_get<0> 106*e4b17023SJohn Marino { 107*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 108*e4b17023SJohn Marino static constexpr _Tp1& 109*e4b17023SJohn Marino __get(std::pair<_Tp1, _Tp2>& __pair) noexcept 110*e4b17023SJohn Marino { return __pair.first; } 111*e4b17023SJohn Marino 112*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 113*e4b17023SJohn Marino static constexpr _Tp1&& 114*e4b17023SJohn Marino __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept 115*e4b17023SJohn Marino { return std::forward<_Tp1>(__pair.first); } 116*e4b17023SJohn Marino 117*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 118*e4b17023SJohn Marino static constexpr const _Tp1& 119*e4b17023SJohn Marino __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept 120*e4b17023SJohn Marino { return __pair.first; } 121*e4b17023SJohn Marino }; 122*e4b17023SJohn Marino 123*e4b17023SJohn Marino template<> 124*e4b17023SJohn Marino struct __pair_get<1> 125*e4b17023SJohn Marino { 126*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 127*e4b17023SJohn Marino static constexpr _Tp2& 128*e4b17023SJohn Marino __get(std::pair<_Tp1, _Tp2>& __pair) noexcept 129*e4b17023SJohn Marino { return __pair.second; } 130*e4b17023SJohn Marino 131*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 132*e4b17023SJohn Marino static constexpr _Tp2&& 133*e4b17023SJohn Marino __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept 134*e4b17023SJohn Marino { return std::forward<_Tp2>(__pair.second); } 135*e4b17023SJohn Marino 136*e4b17023SJohn Marino template<typename _Tp1, typename _Tp2> 137*e4b17023SJohn Marino static constexpr const _Tp2& 138*e4b17023SJohn Marino __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept 139*e4b17023SJohn Marino { return __pair.second; } 140*e4b17023SJohn Marino }; 141*e4b17023SJohn Marino 142*e4b17023SJohn Marino template<std::size_t _Int, class _Tp1, class _Tp2> 143*e4b17023SJohn Marino constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& 144*e4b17023SJohn Marino get(std::pair<_Tp1, _Tp2>& __in) noexcept 145*e4b17023SJohn Marino { return __pair_get<_Int>::__get(__in); } 146*e4b17023SJohn Marino 147*e4b17023SJohn Marino template<std::size_t _Int, class _Tp1, class _Tp2> 148*e4b17023SJohn Marino constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&& 149*e4b17023SJohn Marino get(std::pair<_Tp1, _Tp2>&& __in) noexcept 150*e4b17023SJohn Marino { return __pair_get<_Int>::__move_get(std::move(__in)); } 151*e4b17023SJohn Marino 152*e4b17023SJohn Marino template<std::size_t _Int, class _Tp1, class _Tp2> 153*e4b17023SJohn Marino constexpr const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type& 154*e4b17023SJohn Marino get(const std::pair<_Tp1, _Tp2>& __in) noexcept 155*e4b17023SJohn Marino { return __pair_get<_Int>::__const_get(__in); } 156*e4b17023SJohn Marino 157*e4b17023SJohn Marino_GLIBCXX_END_NAMESPACE_VERSION 158*e4b17023SJohn Marino} // namespace 159*e4b17023SJohn Marino 160*e4b17023SJohn Marino#endif 161*e4b17023SJohn Marino 162*e4b17023SJohn Marino#endif /* _GLIBCXX_UTILITY */ 163