# tuple

Go to the documentation of this file.

    00001 // class template tuple -*- C++ -*-
    00002
    00003 // Copyright (C) 2004, 2005 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/tuple
    00031 *  This is a TR1 C++ Library header.
    00032 */
    00033
    00034 // Chris Jefferson <chris@bubblescope.net>
    00035
    00036 #ifndef _TR1_TUPLE
    00037 #define _TR1_TUPLE 1
    00038
    00039 #include <tr1/utility>
    00040 #include <tr1/ref_fwd.h>
    00041
    00042 namespace std
    00043 {
    00044 _GLIBCXX_BEGIN_NAMESPACE(tr1)
    00045
    00046  // An implementation specific class which is used in the tuple class
    00047  // when the tuple is not maximum possible size.
    00048  struct _NullClass { };
    00049
    00050  /// Gives the type of the ith element of a given tuple type.
    00051  template<int __i, typename _Tp>
    00052    struct tuple_element;
    00053
    00054  /// Finds the size of a given tuple type.
    00055  template<typename _Tp>
    00056    struct tuple_size;
    00057
    00058  // Adds a const reference to a non-reference type.
    00059  template<typename _Tp>
    00060    struct __add_c_ref
    00061    { typedef const _Tp& type; };
    00062
    00063  template<typename _Tp>
    00064    struct __add_c_ref<_Tp&>
    00065    { typedef _Tp& type; };
    00066
    00067  // Adds a reference to a non-reference type.
    00068  template<typename _Tp>
    00069    struct __add_ref
    00070    { typedef _Tp& type; };
    00071
    00072  template<typename _Tp>
    00073    struct __add_ref<_Tp&>
    00074    { typedef _Tp& type; };
    00075
    00076  // Class used in the implementation of get
    00077  template<int __i, typename _Tp>
    00078    struct __get_helper;
    00079
    00080  // Returns a const reference to the ith element of a tuple.
    00081  // Any const or non-const ref elements are returned with their original type.
    00082
    00083  // This class helps construct the various comparison operations on tuples
    00084  template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
    00085    struct __tuple_compare;
    00086
    00087  // Helper which adds a reference to a type when given a reference_wrapper
    00088  template<typename _Tp>
    00089    struct __strip_reference_wrapper
    00090    {
    00091        typedef _Tp __type;
    00092    };
    00093
    00094  template<typename _Tp>
    00095    struct __strip_reference_wrapper<reference_wrapper<_Tp> >
    00096    {
    00097      typedef _Tp& __type;
    00098    };
    00099
    00100  template<typename _Tp>
    00101    struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
    00102    {
    00103        typedef _Tp& __type;
    00104    };
    00105
    00106   #include "tuple_defs.h"
    00107
    00108  template<int __i, int __j, typename _Tp, typename _Up>
    00109    struct __tuple_compare<0, __i, __j, _Tp, _Up>
    00110    {
    00111      static bool __eq(const _Tp& __t, const _Up& __u)
    00112      {
    00113        return get<__i>(__t) == get<__i>(__u) &&
    00114           __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
    00115      }
    00116      static bool __less(const _Tp& __t, const _Up& __u)
    00117      {
    00118        return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
    00119           __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
    00120      }
    00121    };
    00122
    00123  template<int __i, typename _Tp, typename _Up>
    00124    struct __tuple_compare<0, __i, __i, _Tp, _Up>
    00125    {
    00126      static bool __eq(const _Tp&, const _Up&)
    00127      { return true; }
    00128      static bool __less(const _Tp&, const _Up&)
    00129      { return false; }
    00130    };
    00131
    00132  // A class (and instance) which can be used in 'tie' when an element
    00133  // of a tuple is not required
    00134  struct swallow_assign
    00135  {
    00136    template<class T>
    00137    swallow_assign&
    00138      operator=(const T&)
    00139      { return *this; }
    00140  };
    00141
    00142  // TODO: Put this in some kind of shared file.
    00143  namespace
    00144  {
    00145    swallow_assign ignore;
    00146  }; // anonymous namespace
    00147
    00148 _GLIBCXX_END_NAMESPACE
    00149 }
    00150
    00151 #define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
    00152 #define _GLIBCXX_CAT2(x,y) x##y
    00153 #define _SHORT_REPEAT
    00154 #define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
    00155 #include <tr1/repeat.h>
    00156 #undef _GLIBCXX_REPEAT_HEADER
    00157 #undef _SHORT_REPEAT
    00158
    00159 #include <tr1/functional>
    00160
    00161 #endif