valarray (valarray<>::operator=(const valarray<>&), [...]): Implement resolution of DR 630, [Ready] in Frankfurt.

2009-07-22  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/valarray (valarray<>::operator=(const valarray<>&),
	valarray<>::operator=(initializer_list<>)): Implement resolution
	of DR 630, [Ready] in Frankfurt.
	* testsuite/26_numerics/valarray/dr630-1.cc: New.
	* testsuite/26_numerics/valarray/dr630-2.cc: Likewise.
	* doc/xml/manual/intro.xml: Add an entry for DR 630.

From-SVN: r149929
This commit is contained in:
Paolo Carlini 2009-07-22 12:19:58 +00:00 committed by Paolo Carlini
parent 9d0c37619f
commit af4beb4b95
5 changed files with 172 additions and 6 deletions

View File

@ -1,3 +1,12 @@
2009-07-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/valarray (valarray<>::operator=(const valarray<>&),
valarray<>::operator=(initializer_list<>)): Implement resolution
of DR 630, [Ready] in Frankfurt.
* testsuite/26_numerics/valarray/dr630-1.cc: New.
* testsuite/26_numerics/valarray/dr630-2.cc: Likewise.
* doc/xml/manual/intro.xml: Add an entry for DR 630.
2009-07-21 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/chrono (duration<>::operator%=, operator%):

View File

@ -711,6 +711,12 @@ requirements of the license of GCC.
<listitem><para>Add the missing modes to fopen_mode.
</para></listitem></varlistentry>
<varlistentry><term><ulink url="../ext/lwg-active.html#630">630</ulink>:
<emphasis>arrays of valarray</emphasis>
</term>
<listitem><para>Implement the simple resolution.
</para></listitem></varlistentry>
<varlistentry><term><ulink url="../ext/lwg-defects.html#660">660</ulink>:
<emphasis>Missing bitwise operations</emphasis>
</term>

View File

@ -1,7 +1,7 @@
// The template and inlines for the -*- C++ -*- valarray class.
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
// 2006, 2007, 2009
// 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -647,7 +647,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp>
inline
valarray<_Tp>::valarray(initializer_list<_Tp> __l)
: _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
: _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
{ std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
#endif
@ -669,8 +669,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline valarray<_Tp>&
valarray<_Tp>::operator=(const valarray<_Tp>& __v)
{
_GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size);
std::__valarray_copy(__v._M_data, _M_size, _M_data);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 630. arrays of valarray.
if (_M_size == __v._M_size)
std::__valarray_copy(__v._M_data, _M_size, _M_data);
else
{
if (_M_data)
{
std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
std::__valarray_release_memory(_M_data);
}
_M_size = __v._M_size;
_M_data = __valarray_get_storage<_Tp>(_M_size);
std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
_M_data);
}
return *this;
}
@ -679,8 +693,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
inline valarray<_Tp>&
valarray<_Tp>::operator=(initializer_list<_Tp> __l)
{
_GLIBCXX_DEBUG_ASSERT(_M_size == __l.size());
std::__valarray_copy(__l.begin(), __l.size(), _M_data);
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 630. arrays of valarray.
if (_M_size == __l.size())
std::__valarray_copy(__l.begin(), __l.size(), _M_data);
else
{
if (_M_data)
{
std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
std::__valarray_release_memory(_M_data);
}
_M_size = __l.size();
_M_data = __valarray_get_storage<_Tp>(_M_size);
std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size,
_M_data);
}
return *this;
}
#endif

View File

@ -0,0 +1,60 @@
// Copyright (C) 2009 Free Software Foundation
//
// 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/>.
#include <valarray>
#include <testsuite_hooks.h>
// DR 630.
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
valarray<int> v1;
const valarray<int> v2(-1, 10000);
v1 = v2;
VERIFY( v1.size() == v2.size() );
VERIFY( (v1 == v2).min() == true );
valarray<int> v3(0, 10000);
const valarray<int> v4;
v3 = v4;
VERIFY( v3.size() == v4.size() );
VERIFY( v3.size() == 0 );
valarray<int> v5(0, 100);
const valarray<int> v6(-1, 10000);
v5 = v6;
VERIFY( v5.size() == v6.size() );
VERIFY( (v5 == v6).min() == true );
valarray<int> v7(0, 10000);
const valarray<int> v8(-1, 100);
v7 = v8;
VERIFY( v7.size() == v8.size() );
VERIFY( (v7 == v8).min() == true );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,62 @@
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2009 Free Software Foundation
//
// 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/>.
#include <valarray>
#include <testsuite_hooks.h>
// DR 630.
void test01()
{
bool test __attribute__((unused)) = true;
using namespace std;
valarray<int> v1;
v1 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
VERIFY( v1.size() == 10 );
VERIFY( v1.min() == -1 );
VERIFY( v1.max() == -1 );
valarray<int> v2(0, 10);
v2 = { -1, -1, -1, -1, -1 };
VERIFY( v2.size() == 5 );
VERIFY( v2.min() == -1 );
VERIFY( v2.max() == -1 );
valarray<int> v3(0, 5);
v3 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
VERIFY( v3.size() == 10 );
VERIFY( v3.min() == -1 );
VERIFY( v3.max() == -1 );
valarray<int> v4(0, 10);
v4 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
VERIFY( v4.size() == 10 );
VERIFY( v4.min() == -1 );
VERIFY( v4.max() == -1 );
}
int main()
{
test01();
return 0;
}