# tr1_impl/utility

Go to the documentation of this file.

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