gcc/libstdc++-v3/include/tr1/tuple
Doug Gregor 59cffcf69a [multiple changes]
2005-03-31  Chris Jefferson  <chris@bubblescope.net>

        * include/tr1/tuple: Support iteration via tuple_iterate.h.
        * include/tr1/tuple_iterate.h: Iteration file for tuple.

2005-03-31  Douglas Gregor  <doug.gregor@gmail.com>

        * include/Makefile.am (tr1_headers): Add bind and mu repetition
        headers and reference_wrapper<> forwarding header.
        * include/Makefile.in: Regenerate.
        * include/tr1/bind_iterate.h: Implementation of function call
        operators for the function object returned from tr1::bind().
        * include/tr1/bind_repeat.h: Bind-specific repetition header,
        akin to include/tr1/repeat.h.
        * include/tr1/functional (_Mem_fn): Bug fix: declare result
member
        template for use with result_of.
        (is_bind_expression): New.
        (is_placeholder): New.
        (_Placeholder): New. Placeholder type for bind.
        (_Mu): New. Implementation detail of bind.
        (_Bind, _Bind_result): New. Function objects returned by bind.
        (_GLIBCXX_JOIN): New. Required to create bind placeholders.
        * include/tr1/functional_iterate.h (_Bind, _Bind_result, bind):
        New. Implementation of tr1::bind.
        * include/tr1/mu_iterate.h (_Mu): result template and operator()
        for the _Mu helper to bind.
        * include/tr1/ref_fwd.h (reference_wrapper): Forward declaration
        used by tuple header.
        (ref): Ditto.
        (cref): Ditto.
        * include/tr1/repeat.h: Add bind-specific repetition macros.
        * include/tr1/tuple: Use reference_wrapper forwarding header for
        initial definitions, then include <tr1/functional> at the end, to
        make the circular dependencies work.
        (tie): Support zero-argument tie() function.
        * testsuite/tr1/3_function_objects/bind/all_bound.cc: New test of
        bind() functionality with parameters bound.
        * testsuite/tr1/3_function_objects/bind/nested.cc: New test of
        nested bind() expressions.
        * testsuite/tr1/3_function_objects/bind/placeholders.cc: New test
        of bind() placeholders.
        * testsuite/tr1/3_function_objects/bind/ref.cc: New test of bind()
        with arguments bound via reference_wrapper<>.
        * scripts/gen_includers.pl: Generate the repetitive part of
	include/tr1/repeat.h.
	* scripts/gen_bind_includers.pl: Generate the repetitive part of
	include/tr1/bind_repeat.h.

From-SVN: r97361
2005-04-01 03:35:59 +00:00

276 lines
11 KiB
C++

// class template tuple -*- C++ -*-
// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/** @file
* This is a TR1 C++ Library header.
*/
// Chris Jefferson <chris@bubblescope.net>
#ifndef _TUPLE
#define _TUPLE 1
#include <tr1/utility>
#include <tr1/ref_fwd.h>
namespace std
{
namespace tr1
{
// An implementation specific class which is used in the tuple class
// when the tuple is not maximum possible size.
struct _NullClass { };
template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
class tuple;
/// Gives the type of the ith element of a given tuple type.
template<int __i, typename _Tp>
struct tuple_element;
/// Finds the size of a given tuple type.
template<typename _Tp>
struct tuple_size;
// Adds a const reference to a non-reference type.
template<typename _Tp>
struct __add_c_ref
{ typedef const _Tp& type; };
template<typename _Tp>
struct __add_c_ref<_Tp&>
{ typedef _Tp& type; };
// Adds a reference to a non-reference type.
template<typename _Tp>
struct __add_ref
{ typedef _Tp& type; };
template<typename _Tp>
struct __add_ref<_Tp&>
{ typedef _Tp& type; };
// Class used in the implementation of get
template<int __i, typename _Tp>
struct __get_helper;
// Returns a const reference to the ith element of a tuple.
// Any const or non-const ref elements are returned with their original type.
template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9>
typename __add_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
_Tp3, _Tp4, _Tp5,
_Tp6, _Tp7, _Tp8,
_Tp9> >::type>::type
get(tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9>& __t)
{
return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
_Tp7, _Tp8, _Tp9> >::get_value(__t);
}
template<int __i, typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9>
typename __add_c_ref<typename tuple_element<__i, tuple<_Tp0, _Tp1, _Tp2,
_Tp3, _Tp4, _Tp5,
_Tp6, _Tp7, _Tp8,
_Tp9> >::type>::type
get(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9>& __t)
{
return __get_helper<__i, tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6,
_Tp7, _Tp8, _Tp9> >::get_value(__t);
}
// This class helps construct the various comparison operations on tuples
template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
struct __tuple_compare;
template<int __i, int __j, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __j, _Tp, _Up>
{
static bool __eq(const _Tp& __t, const _Up& __u)
{
return get<__i>(__t) == get<__i>(__u) &&
__tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
}
static bool __less(const _Tp& __t, const _Up& __u)
{
return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
__tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
}
};
template<int __i, typename _Tp, typename _Up>
struct __tuple_compare<0, __i, __i, _Tp, _Up>
{
static bool __eq(const _Tp&, const _Up&)
{ return true; }
static bool __less(const _Tp&, const _Up&)
{ return false; }
};
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator==(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{
typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u);
}
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator<(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{
typedef tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10> _Tp;
typedef tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8,_U9, _U10> _Up;
return __tuple_compare<tuple_size<_Tp>::value - tuple_size<_Tp>::value, 0,
tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u);
}
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator!=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{ return !(__t == __u); }
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator>(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{ return __u < __t; }
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator<=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{ return !(__u < __t); }
template<typename _T1, typename _T2, typename _T3, typename _T4, typename _T5,
typename _T6, typename _T7, typename _T8, typename _T9, typename _T10,
typename _U1, typename _U2, typename _U3, typename _U4, typename _U5,
typename _U6, typename _U7, typename _U8, typename _U9, typename _U10>
bool
operator>=(const tuple<_T1, _T2, _T3, _T4, _T5, _T6, _T7, _T8, _T9, _T10>& __t,
const tuple<_U1, _U2, _U3, _U4, _U5, _U6, _U7, _U8, _U9, _U10>& __u)
{ return !(__t < __u); }
// Helper which adds a reference to a type when given a reference_wrapper
template<typename _Tp>
struct __strip_reference_wrapper
{
typedef _Tp __type;
};
template<typename _Tp>
struct __strip_reference_wrapper<reference_wrapper<_Tp> >
{
typedef _Tp& __type;
};
template<typename _Tp>
struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
{
typedef _Tp& __type;
};
template<typename _Tp0 = _NullClass, typename _Tp1 = _NullClass,
typename _Tp2 = _NullClass, typename _Tp3 = _NullClass,
typename _Tp4 = _NullClass, typename _Tp5 = _NullClass,
typename _Tp6 = _NullClass, typename _Tp7 = _NullClass,
typename _Tp8 = _NullClass, typename _Tp9 = _NullClass>
struct __stripped_tuple_type
{
typedef tuple<typename __strip_reference_wrapper<_Tp0>::__type,
typename __strip_reference_wrapper<_Tp1>::__type,
typename __strip_reference_wrapper<_Tp2>::__type,
typename __strip_reference_wrapper<_Tp3>::__type,
typename __strip_reference_wrapper<_Tp4>::__type,
typename __strip_reference_wrapper<_Tp5>::__type,
typename __strip_reference_wrapper<_Tp6>::__type,
typename __strip_reference_wrapper<_Tp7>::__type,
typename __strip_reference_wrapper<_Tp8>::__type,
typename __strip_reference_wrapper<_Tp9>::__type> __type;
};
// A class (and instance) which can be used in 'tie' when an element
// of a tuple is not required
struct swallow_assign
{
template<class T>
swallow_assign&
operator=(const T&)
{ return *this; }
};
// TODO: Put this in some kind of shared file.
namespace
{
swallow_assign ignore;
};
#define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
#define _GLIBCXX_CAT2(x,y) x##y
#define _SHORT_REPEAT
#define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
#include <tr1/repeat.h>
#undef _GLIBCXX_REPEAT_HEADER
#undef _SHORT_REPEAT
}
}
#include <tr1/functional>
#endif