diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cc8b6b22412..66f57c7f1eb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2006-02-24 Paolo Carlini + + * 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 * testsuite/22_locale/codecvt/in/wchar_t/1.cc (test01): Change int diff --git a/libstdc++-v3/include/tr1/array b/libstdc++-v3/include/tr1/array index 5f504851847..9332efeb4ab 100644 --- a/libstdc++-v3/include/tr1/array +++ b/libstdc++-v3/include/tr1/array @@ -50,15 +50,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) template struct array { - typedef _Tp value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* iterator; - typedef const value_type* const_iterator; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; + typedef _Tp value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* iterator; + typedef const value_type* const_iterator; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; // Compile time constant without other dependencies. enum { _S_index = _Nm }; @@ -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 - bool + inline bool operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return std::equal(__one.begin(), __one.end(), __two.begin()); } template - bool + inline bool operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one == __two); } template - 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 - bool + inline bool operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return __two < __one; } template - bool + inline bool operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one > __two); } template - bool + inline bool operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two) { return !(__one < __two); } // Specialized algorithms [6.2.2.2]. template - 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 class tuple_size; @@ -220,12 +222,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) { typedef _Tp type; }; template - _Tp& + inline _Tp& get(array<_Tp, _Nm>& __arr) { return __arr[_Int]; } template - const _Tp& + inline const _Tp& get(const array<_Tp, _Nm>& __arr) { return __arr[_Int]; } diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/assign.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/assign.cc new file mode 100644 index 00000000000..e65c54e9aee --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/assign.cc @@ -0,0 +1,47 @@ +// 2006-02-24 Paolo Carlini +// +// 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 +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + const size_t len = 3; + typedef std::tr1::array 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; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/member_swap.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/member_swap.cc new file mode 100644 index 00000000000..3baa3cb2b3a --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/requirements/member_swap.cc @@ -0,0 +1,49 @@ +// 2006-02-24 Paolo Carlini +// +// 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 +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + const size_t len = 5; + typedef std::tr1::array 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; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/array/specialized_algorithms/swap.cc b/libstdc++-v3/testsuite/tr1/6_containers/array/specialized_algorithms/swap.cc new file mode 100644 index 00000000000..6ec9968f4c7 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/array/specialized_algorithms/swap.cc @@ -0,0 +1,49 @@ +// 2006-02-24 Paolo Carlini +// +// 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 +#include + +void +test01() +{ + bool test __attribute__((unused)) = true; + + const size_t len = 5; + typedef std::tr1::array 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; +}