[multiple changes]

2004-11-24  Benjamin Kosnik  <bkoz@redhat.com>

	* include/Makefile.am (tr1_headers): Add utility, functional.
	* include/Makefile.in: Regenerate.

2004-11-24  Chris Jefferson  <chris@bubblescope.net>

	* include/tr1/tuple(operator!=): Change operator
	definition to match (draft) technical report.
	(operator>): Same.
	(operator<=): Same.
	(operator>=): Same.
	(ref): Move to include/tr1/functional.
	(cref): Same.
	(tuple_size<pair>): Move to include/tr1/utility.
	(tuple_element<,pair>): Same.
	* include/tr1/functional: New.
	* include/tr1/utility: New.
	* testsuite/tr1/6_container/utility/pair.cc: New.

From-SVN: r91171
This commit is contained in:
Benjamin Kosnik 2004-11-24 16:04:47 +00:00
parent 624b15fa3f
commit f2ede5d621
7 changed files with 290 additions and 156 deletions

View File

@ -1,3 +1,23 @@
2004-11-24 Benjamin Kosnik <bkoz@redhat.com>
* include/Makefile.am (tr1_headers): Add utility, functional.
* include/Makefile.in: Regenerate.
2004-11-24 Chris Jefferson <chris@bubblescope.net>
* include/tr1/tuple(operator!=): Change operator
definition to match (draft) technical report.
(operator>): Same.
(operator<=): Same.
(operator>=): Same.
(ref): Move to include/tr1/functional.
(cref): Same.
(tuple_size<pair>): Move to include/tr1/utility.
(tuple_element<,pair>): Same.
* include/tr1/functional: New.
* include/tr1/utility: New.
* testsuite/tr1/6_container/utility/pair.cc: New.
2004-11-24 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
* config/locale/ieee_1003.1-2001/codecvt_specializations.h

View File

@ -229,7 +229,10 @@ tr1_srcdir = ${glibcxx_srcdir}/include/tr1
tr1_builddir = ./tr1
tr1_headers = \
${tr1_srcdir}/array \
${tr1_srcdir}/tuple
${tr1_srcdir}/functional \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility
# This is the common subset of files that all three "C" header models use.
c_base_srcdir = $(C_INCLUDE_DIR)

View File

@ -446,7 +446,9 @@ tr1_srcdir = ${glibcxx_srcdir}/include/tr1
tr1_builddir = ./tr1
tr1_headers = \
${tr1_srcdir}/array \
${tr1_srcdir}/tuple
${tr1_srcdir}/functional \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility
# This is the common subset of files that all three "C" header models use.

View File

@ -0,0 +1,85 @@
// TR1 functional header -*- C++ -*-
// Copyright (C) 2004 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.
/** @file
* This is a TR1 C++ Library header.
*/
#ifndef _TR1_FUNCTIONAL
#define _TR1_FUNCTIONAL 1
#include "../functional"
namespace std
{
namespace tr1
{
template<typename _Tp>
class reference_wrapper
{
_Tp* _M_data;
public:
typedef _Tp type;
explicit reference_wrapper(_Tp& __indata): _M_data(&__indata)
{ }
reference_wrapper(const reference_wrapper<_Tp>& __inref):
_M_data(__inref._M_data)
{ }
reference_wrapper&
operator=(const reference_wrapper<_Tp>& __inref)
{
_M_data = __inref._M_data;
return *this;
}
operator _Tp&() const
{ return this->get(); }
_Tp&
get() const
{ return *_M_data; }
};
// Denotes a reference should be taken to a variable.
template<typename _Tp>
reference_wrapper<_Tp>
ref(_Tp& __t)
{ return reference_wrapper<_Tp>(__t); }
// Denotes a const reference should be taken to a variable.
template<typename _Tp>
reference_wrapper<const _Tp>
cref(const _Tp& __t)
{ return reference_wrapper<const _Tp>(__t); }
template<typename _Tp>
reference_wrapper<_Tp> ref(reference_wrapper<_Tp> __t)
{ return ref(__t.get()); }
template<typename _Tp>
reference_wrapper<const _Tp> cref(reference_wrapper<_Tp> __t)
{ return cref(__t.get()); }
}
}
#endif

View File

@ -18,18 +18,19 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// Chris Jefferson <chris@bubblescope.net>
// This header is automatically generated: see maketuple.c for details.
/** @file
* This is a TR1 C++ Library header.
*/
// Chris Jefferson <chris@bubblescope.net>
// This header is automatically generated: see maketuple.c for details.
#ifndef _TUPLE
#define _TUPLE 1
#include<utility>
#include <tr1/utility>
#include <tr1/functional>
namespace std
{
@ -1046,9 +1047,8 @@ namespace tr1
{ return __in._M_t9; }
};
/* Returns a reference to the ith element of a tuple.
* Any const or non-const ref elements are returned with their original type
*/
// Returns a 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>
@ -1063,9 +1063,8 @@ namespace tr1
_Tp7, _Tp8, _Tp9> >::get_value(__t);
}
/* Returns a const reference to the ith element of a tuple.
* Any const or non-const ref elements are returned with their original type
*/
// 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>
@ -1092,31 +1091,11 @@ namespace tr1
return get<__i>(__t) == get<__i>(__u) &&
__tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
}
static bool __neq(const _Tp& __t, const _Up& __u)
{
return get<__i>(__t) != get<__i>(__u) ||
__tuple_compare<0, __i+1, __j, _Tp, _Up>::__neq(__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);
}
static bool __greater(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>::__greater(__t, __u);
}
static bool __leq(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>::__leq(__t, __u));
}
static bool __geq(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>::__geq(__t, __u));
}
};
template<int __i, typename _Tp, typename _Up>
@ -1124,16 +1103,8 @@ namespace tr1
{
static bool __eq(const _Tp&, const _Up&)
{ return true; }
static bool __neq(const _Tp&, const _Up&)
{ return false; }
static bool __leq(const _Tp&, const _Up&)
{ return true; }
static bool __geq(const _Tp&, const _Up&)
{ return true; }
static bool __less(const _Tp&, const _Up&)
{ return false; }
static bool __greater(const _Tp&, const _Up&)
{ return false; }
};
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
@ -1146,30 +1117,12 @@ namespace tr1
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
_Tp9> _Tp;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__eq(__t, __u);
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9, typename _Up0, typename _Up1,
typename _Up2, typename _Up3, typename _Up4, typename _Up5,
typename _Up6, typename _Up7, typename _Up8, typename _Up9>
bool
operator!=(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t,
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__neq(__t, __u);
_Up9> _Up;
return __tuple_compare<tuple_size<_Tp>::value -
tuple_size<_Tp>::value, 0,
tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u);
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
@ -1182,14 +1135,25 @@ namespace tr1
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
_Tp9> _Tp;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__less(__t, __u);
_Up9> _Up;
return __tuple_compare<tuple_size<_Tp>::value -
tuple_size<_Tp>::value, 0,
tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u);
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9, typename _Up0, typename _Up1,
typename _Up2, typename _Up3, typename _Up4, typename _Up5,
typename _Up6, typename _Up7, typename _Up8, typename _Up9>
bool
operator!=(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t,
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
return !(__t == __u);
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9, typename _Up0, typename _Up1,
@ -1199,15 +1163,8 @@ namespace tr1
operator>(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t,
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__greater(__t, __u);
return __u < __t;
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9, typename _Up0, typename _Up1,
@ -1217,15 +1174,8 @@ namespace tr1
operator<=(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t,
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__leq(__t, __u);
return !(__u < __t);
}
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
typename _Tp8, typename _Tp9, typename _Up0, typename _Up1,
@ -1235,54 +1185,9 @@ namespace tr1
operator>=(const tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8, _Tp9>& __t,
const tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8, _Up9>& __u)
{
typedef tuple<_Tp0, _Tp1, _Tp2, _Tp3, _Tp4, _Tp5, _Tp6, _Tp7, _Tp8,
_Tp9> __t_tuple;
typedef tuple<_Up0, _Up1, _Up2, _Up3, _Up4, _Up5, _Up6, _Up7, _Up8,
_Up9> __u_tuple;
return __tuple_compare<tuple_size<__t_tuple>::value -
tuple_size<__u_tuple>::value, 0,
tuple_size<__t_tuple>::value, __t_tuple, __u_tuple>::__geq(__t, __u);
return !(__t < __u);
}
// Provides a way to annotate that a reference to
// an object should be passed.
template<typename _Tp>
class reference_wrapper
{
_Tp& _M_data;
public:
typedef _Tp type;
explicit reference_wrapper(_Tp& __indata): _M_data(__indata)
{ }
operator _Tp& () const
{
return this->get();
}
_Tp&
get() const
{
return _M_data;
}
};
// Denotes a reference should be taken to a variable.
template<typename _Tp>
reference_wrapper<_Tp>
ref(_Tp& __t)
{
return reference_wrapper<_Tp>(__t);
}
// Denotes a const reference should be taken to a variable.
template<typename _Tp>
reference_wrapper<_Tp const>
cref(const _Tp& __t)
{
return reference_wrapper<_Tp const>(__t);
}
// Helper which adds a reference to a type when given a reference_wrapper
template<typename _Tp>
struct __strip_reference_wrapper
@ -1430,7 +1335,6 @@ namespace tr1
// 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>
@ -1439,7 +1343,7 @@ namespace tr1
{ return *this; }
};
// TODO: Put this in some kind of shared file
// TODO: Put this in some kind of shared file.
namespace
{
swallow_assign ignore;
@ -1538,29 +1442,6 @@ namespace tr1
ref(__t9));
};
// Various functions which give std::pair a tuple-like interface.
template<class _Tp1, class _Tp2>
struct tuple_size<std::pair<_Tp1, _Tp2> >
{ static const int value = 2; };
template<class _Tp1, class _Tp2>
struct tuple_element<0, std::pair<_Tp1, _Tp2> >
{ typedef _Tp1 type; };
template<class _Tp1, class _Tp2>
struct tuple_element<1, std::pair<_Tp1, _Tp2> >
{ typedef _Tp2 type; };
template<int _Int, class _Tp1, class _Tp2>
typename tuple_element<_Int, tuple<_Tp1, _Tp2> >::type
get(pair<_Tp1, _Tp2>& __in)
{ return get<_Int>(tie(__in.first, __in.second)); }
template<int _Int, class _Tp1, class _Tp2>
typename tuple_element<_Int, tuple<_Tp1, _Tp2> >::type
get(const pair<_Tp1, _Tp2>& __in)
{ return get<_Int>(tie(__in.first, __in.second)); }
}
}

View File

@ -0,0 +1,89 @@
// TR1 utility -*- C++ -*-
// Copyright (C) 2004 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.
/** @file
* This is a TR1 C++ Library header.
*/
#ifndef _TR1_UTILITY
#define _TR1_UTILITY 1
#include "../utility"
namespace std
{
namespace tr1
{
template<class _Tp> class tuple_size;
template<int _Int, class _Tp> class tuple_element;
// Various functions which give std::pair a tuple-like interface.
template<class _Tp1, class _Tp2>
struct tuple_size<std::pair<_Tp1, _Tp2> >
{ static const int value = 2; };
template<class _Tp1, class _Tp2>
struct tuple_element<0, std::pair<_Tp1, _Tp2> >
{ typedef _Tp1 type; };
template<class _Tp1, class _Tp2>
struct tuple_element<1, std::pair<_Tp1, _Tp2> >
{ typedef _Tp2 type; };
template<int _Int> struct __pair_get;
template<>
struct __pair_get<0>
{
template<typename _Tp1, typename _Tp2>
static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
{ return __pair.first; }
template<typename _Tp1, typename _Tp2>
static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
{ return __pair.first; }
};
template<>
struct __pair_get<1>
{
template<typename _Tp1, typename _Tp2>
static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
{ return __pair.second; }
template<typename _Tp1, typename _Tp2>
static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
{ return __pair.second; }
};
template<int _I, class _Tp1, class _Tp2>
typename tuple_element<_I, std::pair<_Tp1, _Tp2> >::type&
get(pair<_Tp1, _Tp2>& __in)
{ return __pair_get<_I>::__get(__in); }
template<int _I, class _Tp1, class _Tp2>
const typename tuple_element<_I, std::pair<_Tp1, _Tp2> >::type&
get(const pair<_Tp1, _Tp2>& __in)
{ return __pair_get<_I>::__const_get(__in); }
}
}
#endif

View File

@ -0,0 +1,54 @@
// 2004-09-23 Chris Jefferson <chris@bubblescope.net>
// Copyright (C) 2004 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.
// tr1 additions to pair
#include <tr1/utility>
#include <testsuite_hooks.h>
using namespace std;
using namespace tr1;
struct blank_class
{ };
int
main()
{
bool test __attribute__((unused)) = true;
typedef pair<int,int> test_pair_type;
VERIFY(tuple_size<test_pair_type>::value == 2);
// Test if tuple_element::type returns the correct type
blank_class blank;
tuple_element<0, pair<blank_class, int> >::type blank2 = blank;
tuple_element<1, pair<int ,blank_class> >::type blank3 = blank;
pair<int,int> test_pair(1, 2);
VERIFY(get<0>(test_pair) == 1);
VERIFY(get<1>(test_pair) == 2);
get<0>(test_pair) = 3;
get<1>(test_pair) = 4;
VERIFY(get<0>(test_pair) == 3);
VERIFY(get<1>(test_pair) == 4);
const pair<int,int> test_pair2(1,2);
VERIFY(get<0>(test_pair2) == 1);
VERIFY(get<1>(test_pair2) == 2);
}