array (array<>::swap, assign): Implement.

2006-02-24  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/array (array<>::swap, assign): Implement.
	* include/tr1/array (operator==, operator!=, operator<,
	operator>, operator>=, operator<=, swap, get): Inline.
	* testsuite/tr1/6_containers/array/requirements/member_swap.cc: New.
	* testsuite/tr1/6_containers/array/requirements/assign.cc: Likewise.
	* testsuite/tr1/6_containers/array/specialized_algorithms/swap.cc:
	Likewise.

From-SVN: r111424
This commit is contained in:
Paolo Carlini 2006-02-24 19:13:49 +00:00 committed by Paolo Carlini
parent e26ec0bb06
commit ffe7d885e0
5 changed files with 178 additions and 21 deletions

View File

@ -1,3 +1,13 @@
2006-02-24 Paolo Carlini <pcarlini@suse.de>
* include/tr1/array (array<>::swap, assign): Implement.
* include/tr1/array (operator==, operator!=, operator<,
operator>, operator>=, operator<=, swap, get): Inline.
* testsuite/tr1/6_containers/array/requirements/member_swap.cc: New.
* testsuite/tr1/6_containers/array/requirements/assign.cc: Likewise.
* testsuite/tr1/6_containers/array/specialized_algorithms/swap.cc:
Likewise.
2006-02-23 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/22_locale/codecvt/in/wchar_t/1.cc (test01): Change int

View File

@ -69,10 +69,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// No explicit construct/copy/destroy for aggregate type.
void
assign(const value_type& u);
assign(const value_type& __u)
{ std::fill_n(begin(), size(), __u); }
void
swap(array&);
swap(array& __other)
{ std::swap_ranges(begin(), end(), __other.begin()); }
// Iterators.
iterator
@ -169,17 +171,17 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// Array comparisons.
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return std::equal(__one.begin(), __one.end(), __two.begin()); }
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return !(__one == __two); }
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
{
return std::lexicographical_compare(__a.begin(), __a.end(),
@ -187,25 +189,25 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
}
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return __two < __one; }
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return !(__one > __two); }
template<typename _Tp, std::size_t _Nm>
bool
inline bool
operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
{ return !(__one < __two); }
// Specialized algorithms [6.2.2.2].
template<typename _Tp, std::size_t _Nm>
void
inline void
swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
{ swap_ranges(__one.begin(), __one.end(), __two.begin()); }
{ std::swap_ranges(__one.begin(), __one.end(), __two.begin()); }
// Tuple interface to class template array [6.2.2.5].
template<typename _Tp> class tuple_size;
@ -220,12 +222,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
{ typedef _Tp type; };
template<int _Int, typename _Tp, std::size_t _Nm>
_Tp&
inline _Tp&
get(array<_Tp, _Nm>& __arr)
{ return __arr[_Int]; }
template<int _Int, typename _Tp, std::size_t _Nm>
const _Tp&
inline const _Tp&
get(const array<_Tp, _Nm>& __arr)
{ return __arr[_Int]; }

View File

@ -0,0 +1,47 @@
// 2006-02-24 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.2.2 Class template array
#include <tr1/array>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
const size_t len = 3;
typedef std::tr1::array<int, len> array_type;
array_type a = { 0, 1, 2 };
const int value = 5;
a.assign(value);
VERIFY( a[0] == value );
VERIFY( a[1] == value );
VERIFY( a[2] == value );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,49 @@
// 2006-02-24 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.2.2 Class template array
#include <tr1/array>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
const size_t len = 5;
typedef std::tr1::array<int, len> array_type;
array_type a = { 0, 1, 2, 3, 4 };
const array_type a_ref = a;
array_type b = { 4, 3, 2, 1, 0 };
const array_type b_ref = b;
a.swap(b);
VERIFY( a == b_ref );
VERIFY( b == a_ref );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,49 @@
// 2006-02-24 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2006 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.2.2.2 array specialized algorithms
#include <tr1/array>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
const size_t len = 5;
typedef std::tr1::array<int, len> array_type;
array_type a = { 0, 1, 2, 3, 4 };
const array_type a_ref = a;
array_type b = { 4, 3, 2, 1, 0 };
const array_type b_ref = b;
std::tr1::swap(a, b);
VERIFY( a == b_ref );
VERIFY( b == a_ref );
}
int main()
{
test01();
return 0;
}