# tr1/utility

Go to the documentation of this file.

    00001 // TR1 utility -*- C++ -*-
    00002
    00003 // Copyright (C) 2004, 2005, 2006, 2007 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 2, 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 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /** @file tr1/utility
    00031  *  This is a TR1 C++ Library header.
    00032  */
    00033
    00034 #ifndef _TR1_UTILITY
    00035 #define _TR1_UTILITY 1
    00036
    00037 #include "../utility"
    00038
    00039 namespace std
    00040 {
    00041 _GLIBCXX_BEGIN_NAMESPACE(tr1)
    00042
    00043   template<class _Tp> class tuple_size;
    00044   template<int _Int, class _Tp> class tuple_element;
    00045
    00046    // Various functions which give std::pair a tuple-like interface.
    00047   template<class _Tp1, class _Tp2>
    00048     struct tuple_size<std::pair<_Tp1, _Tp2> >
    00049     { static const int value = 2; };
    00050
    00051   template<class _Tp1, class _Tp2>
    00052     const int tuple_size<std::pair<_Tp1, _Tp2> >::value;
    00053
    00054   template<class _Tp1, class _Tp2>
    00055     struct tuple_element<0, std::pair<_Tp1, _Tp2> >
    00056     { typedef _Tp1 type; };
    00057
    00058   template<class _Tp1, class _Tp2>
    00059     struct tuple_element<1, std::pair<_Tp1, _Tp2> >
    00060     { typedef _Tp2 type; };
    00061
    00062
    00063   template<int _Int> struct __pair_get;
    00064
    00065   template<>
    00066     struct __pair_get<0>
    00067     {
    00068       template<typename _Tp1, typename _Tp2>
    00069       static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
    00070       { return __pair.first; }
    00071
    00072       template<typename _Tp1, typename _Tp2>
    00073       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
    00074       { return __pair.first; }
    00075     };
    00076
    00077   template<>
    00078     struct __pair_get<1>
    00079     {
    00080       template<typename _Tp1, typename _Tp2>
    00081       static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
    00082       { return __pair.second; }
    00083
    00084       template<typename _Tp1, typename _Tp2>
    00085       static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
    00086       { return __pair.second; }
    00087     };
    00088
    00089    template<int _Int, class _Tp1, class _Tp2>
    00090      inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
    00091      get(std::pair<_Tp1, _Tp2>& __in)
    00092      { return __pair_get<_Int>::__get(__in); }
    00093
    00094    template<int _Int, class _Tp1, class _Tp2>
    00095      inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
    00096      get(const std::pair<_Tp1, _Tp2>& __in)
    00097      { return __pair_get<_Int>::__const_get(__in); }
    00098
    00099 _GLIBCXX_END_NAMESPACE
    00100 }
    00101
    00102 #endif