tuple (tuple_element<__i, [...]): Add.

2011-05-19  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/tuple (tuple_element<__i, const _Tp>,
	tuple_element<__i, volatile _Tp>, tuple_element<__i,
	const volatile _Tp>, tuple_size<const _Tp>, tuple_size<volatile _Tp>,
	tuple_size<const volatile _Tp>): Add.
	* include/std/utility (tuple_size<std::pair<_Tp1, _Tp2>>): Tweak.
	* include/std/array (tuple_size<array<_Tp, _Nm>>): Likewise.
	* testsuite/20_util/tuple/cv_tuple_size.cc: New.
	* testsuite/20_util/tuple/cv_tuple_element.cc: Likewise.
	* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-warning
	line number.

From-SVN: r173919
This commit is contained in:
Paolo Carlini 2011-05-19 20:48:39 +00:00 committed by Paolo Carlini
parent 173f26ae56
commit 664e12c126
7 changed files with 139 additions and 21 deletions

View File

@ -1,3 +1,16 @@
2011-05-19 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/tuple (tuple_element<__i, const _Tp>,
tuple_element<__i, volatile _Tp>, tuple_element<__i,
const volatile _Tp>, tuple_size<const _Tp>, tuple_size<volatile _Tp>,
tuple_size<const volatile _Tp>): Add.
* include/std/utility (tuple_size<std::pair<_Tp1, _Tp2>>): Tweak.
* include/std/array (tuple_size<array<_Tp, _Nm>>): Likewise.
* testsuite/20_util/tuple/cv_tuple_size.cc: New.
* testsuite/20_util/tuple/cv_tuple_element.cc: Likewise.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Tweak dg-warning
line number.
2011-05-19 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/tuple (tuple<>::operator=(tuple&&)): Specify as

View File

@ -242,18 +242,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp>
class tuple_size;
template<typename _Tp, std::size_t _Nm>
struct tuple_size<array<_Tp, _Nm>>
: public integral_constant<std::size_t, _Nm> { };
/// tuple_element
template<std::size_t _Int, typename _Tp>
class tuple_element;
template<typename _Tp, std::size_t _Nm>
struct tuple_size<array<_Tp, _Nm> >
{ static const std::size_t value = _Nm; };
template<typename _Tp, std::size_t _Nm>
const std::size_t
tuple_size<array<_Tp, _Nm> >::value;
template<std::size_t _Int, typename _Tp, std::size_t _Nm>
struct tuple_element<_Int, array<_Tp, _Nm> >
{ typedef _Tp type; };

View File

@ -505,19 +505,53 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef _Head type;
};
template<std::size_t __i, typename _Tp>
struct tuple_element<__i, const _Tp>
{
typedef typename
add_const<typename tuple_element<__i, _Tp>::type>::type type;
};
template<std::size_t __i, typename _Tp>
struct tuple_element<__i, volatile _Tp>
{
typedef typename
add_volatile<typename tuple_element<__i, _Tp>::type>::type type;
};
template<std::size_t __i, typename _Tp>
struct tuple_element<__i, const volatile _Tp>
{
typedef typename
add_cv<typename tuple_element<__i, _Tp>::type>::type type;
};
/// Finds the size of a given tuple type.
template<typename _Tp>
struct tuple_size;
template<typename _Tp>
struct tuple_size<const _Tp>
: public integral_constant<
typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
tuple_size<_Tp>::value> { };
template<typename _Tp>
struct tuple_size<volatile _Tp>
: public integral_constant<
typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
tuple_size<_Tp>::value> { };
template<typename _Tp>
struct tuple_size<const volatile _Tp>
: public integral_constant<
typename remove_cv<decltype(tuple_size<_Tp>::value)>::type,
tuple_size<_Tp>::value> { };
/// class tuple_size
template<typename... _Elements>
struct tuple_size<tuple<_Elements...> >
{
static const std::size_t value = sizeof...(_Elements);
};
template<typename... _Elements>
const std::size_t tuple_size<tuple<_Elements...> >::value;
struct tuple_size<tuple<_Elements...>>
: public integral_constant<std::size_t, sizeof...(_Elements)> { };
template<std::size_t __i, typename _Head, typename... _Tail>
inline typename __add_ref<_Head>::type

View File

@ -88,11 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Various functions which give std::pair a tuple-like interface.
template<class _Tp1, class _Tp2>
struct tuple_size<std::pair<_Tp1, _Tp2>>
{ static const std::size_t value = 2; };
template<class _Tp1, class _Tp2>
const std::size_t
tuple_size<std::pair<_Tp1, _Tp2> >::value;
: public integral_constant<std::size_t, 2> { };
template<class _Tp1, class _Tp2>
struct tuple_element<0, std::pair<_Tp1, _Tp2>>

View File

@ -0,0 +1,34 @@
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// 2011-05-19 Paolo Carlini <paolo.carlini@oracle.com>
//
// Copyright (C) 2011 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 3, 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 COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// Tuple
#include <tuple>
using namespace std;
static_assert(is_same<tuple_element<0, const tuple<double, void, int>>::type,
const double>::value, "Error");
static_assert(is_same<tuple_element<1, volatile tuple<short, void>>::type,
volatile void>::value, "Error");
static_assert(is_same<tuple_element<2, const volatile tuple<float,
char, int>>::type, const volatile int>::value, "Error");

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2011 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 3, 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 COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// Tuple
#include <tuple>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
VERIFY( tuple_size<const tuple<> >::value == 0 );
VERIFY( tuple_size<volatile tuple<int> >::value == 1 );
VERIFY( tuple_size<const volatile tuple<void> >::value == 1 );
typedef tuple<int, const int&, void> test_tuple1;
VERIFY( tuple_size<const test_tuple1>::value == 3 );
VERIFY( tuple_size<const volatile test_tuple1>::value == 3 );
VERIFY( tuple_size<volatile tuple<tuple<void> > >::value == 1 );
}
int main()
{
test01();
return 0;
}

View File

@ -51,7 +51,7 @@ main()
// { dg-warning "note" "" { target *-*-* } 485 }
// { dg-warning "note" "" { target *-*-* } 479 }
// { dg-warning "note" "" { target *-*-* } 469 }
// { dg-warning "note" "" { target *-*-* } 603 }
// { dg-warning "note" "" { target *-*-* } 637 }
// { dg-warning "note" "" { target *-*-* } 1056 }
// { dg-warning "note" "" { target *-*-* } 1050 }
// { dg-warning "note" "" { target *-*-* } 342 }