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