This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC] Add C++14's dynarray container (23.3.4, n3662).
- From: Rüdiger Sonderfeld <ruediger at c-plusplus dot de>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 26 Sep 2013 00:39:44 +0200
- Subject: [RFC] Add C++14's dynarray container (23.3.4, n3662).
- Authentication-results: sourceware.org; auth=none
Hello,
I've also written an implementation for C++14's std::dynarray.
It theoretically supports both memory allocation using `operator new'
and `alloca'. (Switch by #defining USE_ALLOCA at the moment.) However the
alloca implementation is buggy because std::__uninitialized* seems to have
issues initialising the memory.
In theory dynarray should be the C++ equivalent of VLAs. Which would require
stack allocation. But I'm not sure if this can be safely handled at all and
the implementation should instead simply stick to operator new/delete. Maybe
this could be a configuration option (not sure how such a thing would be
handled).
Another problem is the allocator constructor interface. Which seems to be
covered by this LWG issue:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2255
As I have said in my other submission: I have not yet signed the fsf
copyright papers for GCC. But I have requested them.
Looking forward to comments.
Regards,
RÃdiger Sonderfeld
-- 8< --------------------------------------------------------------- >8 --
* libstdc++-v3/include/Makefile.am (std_headers): Add dynarray.
* libstdc++-v3/include/std/dynarray: New header.
* libstdc++-v3/testsuite/23_containers/dynarray/at.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/cons/complexcons.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/cons/cons.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/data/data.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/dynarray_dynarray.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/mutate/mutate.cc: New test.
* libstdc++-v3/testsuite/23_containers/dynarray/riterator.cc: New test.
Signed-off-by: RÃdiger Sonderfeld <ruediger@c-plusplus.de>
---
libstdc++-v3/include/Makefile.am | 1 +
libstdc++-v3/include/std/dynarray | 281 +++++++++++++++++++++
.../testsuite/23_containers/dynarray/at.cc | 80 ++++++
.../23_containers/dynarray/cons/complexcons.cc | 79 ++++++
.../testsuite/23_containers/dynarray/cons/cons.cc | 71 ++++++
.../testsuite/23_containers/dynarray/data/data.cc | 55 ++++
.../23_containers/dynarray/dynarray_dynarray.cc | 47 ++++
.../23_containers/dynarray/mutate/mutate.cc | 51 ++++
.../testsuite/23_containers/dynarray/riterator.cc | 56 ++++
9 files changed, 721 insertions(+)
create mode 100644 libstdc++-v3/include/std/dynarray
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/at.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/cons/complexcons.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/cons/cons.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/data/data.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/dynarray_dynarray.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/mutate/mutate.cc
create mode 100644 libstdc++-v3/testsuite/23_containers/dynarray/riterator.cc
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3be6e57..c3149bd 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -34,6 +34,7 @@ std_headers = \
${std_srcdir}/complex \
${std_srcdir}/condition_variable \
${std_srcdir}/deque \
+ ${std_srcdir}/dynarray \
${std_srcdir}/forward_list \
${std_srcdir}/fstream \
${std_srcdir}/functional \
diff --git a/libstdc++-v3/include/std/dynarray b/libstdc++-v3/include/std/dynarray
new file mode 100644
index 0000000..02e19a5
--- /dev/null
+++ b/libstdc++-v3/include/std/dynarray
@@ -0,0 +1,281 @@
+// <dynarray> -*- C++ -*-
+
+// Copyright (C) 2013 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/optional
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_DYNARRAY
+#define _GLIBCXX_DYNARRAY 1
+
+#pragma GCC system_header
+
+#include <bits/c++14_warning.h>
+#include <bits/c++config.h>
+#include <algorithm>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ template<typename _Tp>
+ class dynarray
+ {
+
+ public:
+ // types:
+ typedef _Tp value_type;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ // TODO __gnu_cxx::__normal_iterator?
+ typedef pointer iterator;
+ typedef const_pointer const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+
+ // 23.3.4.2 [dynarray.cons], construct/copy/destroy:
+ explicit
+ dynarray(size_type __s)
+ : _M_size(__s),
+ _M_data(_M_allocate(_M_size))
+ { std::__uninitialized_default_n(_M_data, _M_size); }
+
+ dynarray(size_type __s, const_reference __v)
+ : _M_size(__s),
+ _M_data(_M_allocate(_M_size))
+ { std::uninitialized_fill_n(_M_data, _M_size, __v); }
+
+ dynarray(const dynarray& __d)
+ : _M_size(__d._M_size),
+ _M_data(_M_allocate(_M_size))
+ { std::uninitialized_copy(__d.begin(), __d.end(), _M_data); }
+
+ dynarray(initializer_list<_Tp> __il)
+ : _M_size(__il.size()),
+ _M_data(_M_allocate(_M_size))
+ { std::uninitialized_copy(__il.begin(), __il.end(), _M_data); }
+
+#if 0
+ template<typename _Alloc>
+ dynarray(size_type __s, const _Alloc& __alloc)
+ : _M_size(__s),
+ _M_data(_M_allocate(_M_size))
+ { std::__uninitialized_default_n_a(_M_data, _M_size, __alloc); }
+
+ template<typename _Alloc>
+ dynarray(size_type __s, const_reference __v, const _Alloc& __alloc)
+ : _M_size(__s),
+ _M_data(_M_allocate(_M_size))
+ { std::__uninitialized_fill_n_a(_M_data, _M_size, __v, __alloc); }
+
+ template<typename _Alloc>
+ dynarray(const dynarray& __d, const _Alloc& __alloc)
+ : _M_size(__d._M_size),
+ _M_data(_M_allocate(_M_size))
+ { std::__uninitialized_copy_a(__d.begin(), __d.end(), _M_data, __alloc); }
+
+ template<typename _Alloc>
+ dynarray(initializer_list<_Tp> __il, const _Alloc& __alloc)
+ : _M_size(__il.size()),
+ _M_data(_M_allocate(_M_size))
+ { std::__uninitialized_copy_a(__il.begin(), __il.end(), _M_data, __alloc); }
+#endif
+
+ dynarray& operator=(const dynarray&) = delete;
+
+ ~dynarray()
+ {
+ std::_Destroy(this->begin(), this->end());
+ _M_deallocate(_M_data, _M_size);
+ }
+
+ // iterators
+ iterator
+ begin() noexcept
+ { return _M_data; }
+
+ const_iterator
+ begin() const noexcept
+ { return this->cbegin(); }
+
+ const_iterator
+ cbegin() const noexcept
+ { return _M_data; }
+
+ iterator
+ end() noexcept
+ { return _M_data + _M_size; }
+
+ const_iterator
+ end() const noexcept
+ { return this->cend(); }
+
+ const_iterator
+ cend() const noexcept
+ { return _M_data + _M_size; }
+
+ reverse_iterator
+ rbegin() noexcept
+ { return reverse_iterator(this->end()); }
+
+ const_reverse_iterator
+ rbegin() const noexcept
+ { return this->crbegin(); }
+
+ const_reverse_iterator
+ crbegin() const noexcept
+ { return const_reverse_iterator(this->end()); }
+
+ reverse_iterator
+ rend() noexcept
+ { return reverse_iterator(this->begin()); }
+
+ const_reverse_iterator
+ rend() const noexcept
+ { return this->crend(); }
+
+ const_reverse_iterator
+ crend() const noexcept
+ { return const_reverse_iterator(this->begin()); }
+
+ // capacity:
+ size_type
+ size() const noexcept
+ { return _M_size; }
+
+ size_type
+ max_size() const noexcept
+ { return _M_size; }
+
+ bool
+ empty() const noexcept
+ { return _M_size == 0; }
+
+ // element access:
+ reference
+ operator[](size_type __n)
+ { return _M_data[__n]; }
+
+ const_reference
+ operator[](size_type __n) const
+ { return _M_data[__n]; }
+
+ reference
+ front()
+ { return *_M_data; }
+
+ const_reference
+ front() const
+ { return *_M_data; }
+
+ reference
+ back()
+ { return _M_data[_M_size - 1]; }
+
+ const_reference
+ back() const
+ { return _M_data[_M_size - 1]; }
+
+ const_reference
+ at(size_type __n) const
+ {
+ if (__n >= _M_size)
+ std::__throw_out_of_range_fmt(__N("dynarray::at: __n (which is %zu) "
+ ">= _M_size (which is %zu)"),
+ __n, _M_size);
+ return _M_data[__n];
+ }
+
+ reference
+ at(size_type __n)
+ {
+ if (__n >= _M_size)
+ std::__throw_out_of_range_fmt(__N("dynarray::at: __n (which is %zu) "
+ ">= _M_size (which is %zu)"),
+ __n, _M_size);
+ return _M_data[__n];
+ }
+
+ // 23.3.4.3 [dynarray.data], data access:
+ pointer
+ data() noexcept
+ { return _M_data; }
+
+ const_pointer
+ data() const noexcept
+ { return _M_data; }
+
+ // 23.3.4.4 [dynarray.mutate], mutating member functions:
+ void
+ fill(const_reference __v)
+ { std::fill_n(this->begin(), this->size(), __v); }
+
+ private:
+ size_type _M_size;
+ pointer _M_data;
+
+#ifdef _USE_ALLOCA
+ static pointer
+ _M_allocate(size_type __s)
+ {
+ if (__s == 0)
+ return nullptr;
+ else
+ return static_cast<pointer>(__builtin_alloca(__s));
+ }
+
+ static void
+ _M_deallocate(pointer, size_type) noexcept
+ { }
+#else
+ static pointer
+ _M_allocate(size_type __s)
+ {
+ if (__s == 0)
+ return nullptr;
+ else
+ return static_cast<pointer>(::operator new(sizeof(value_type) * __s));
+ }
+
+ static void
+ _M_deallocate(pointer __p, size_type) noexcept
+ {
+ ::operator delete(static_cast<void*>(__p));
+ }
+#endif
+ };
+
+ template<typename _Tp, typename _Alloc>
+ struct uses_allocator<dynarray<_Tp>, _Alloc> : true_type
+ { };
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+
+
+#endif // _GLIBCXX_DYNARRAY
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/at.cc b/libstdc++-v3/testsuite/23_containers/dynarray/at.cc
new file mode 100644
index 0000000..55b4eae
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/at.cc
@@ -0,0 +1,80 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+struct X { };
+
+void
+test01()
+{
+ dynarray<X> a(3);
+ bool throwed = false;
+ try
+ {
+ a.at(2);
+ }
+ catch(std::out_of_range&)
+ {
+ throwed = true;
+ }
+ VERIFY( not throwed );
+
+ try
+ {
+ a.at(3);
+ }
+ catch(std::out_of_range&)
+ {
+ throwed = true;
+ }
+ VERIFY( throwed );
+
+ dynarray<X> const b(4);
+ throwed = false;
+ try
+ {
+ b.at(0);
+ }
+ catch(std::out_of_range&)
+ {
+ throwed = true;
+ }
+ VERIFY( not throwed );
+
+ try
+ {
+ b.at(100);
+ }
+ catch(std::out_of_range&)
+ {
+ throwed = true;
+ }
+ VERIFY( throwed );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/cons/complexcons.cc b/libstdc++-v3/testsuite/23_containers/dynarray/cons/complexcons.cc
new file mode 100644
index 0000000..a3797bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/cons/complexcons.cc
@@ -0,0 +1,79 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+struct Test
+{
+ static int ctor;
+ static int copy;
+ static int dtor;
+
+ int a = 0;
+ int b = 0;
+
+ Test(int a = 0, int b = 0)
+ : a(a), b(b)
+ { ++ctor; }
+ Test(const Test& o)
+ : a(o.a), b(o.b)
+ { ++copy; }
+ ~Test()
+ { ++dtor; }
+};
+
+int Test::ctor = 0;
+int Test::copy = 0;
+int Test::dtor = 0;
+
+void
+test01()
+{
+ dynarray<Test> o0(0);
+ VERIFY( o0.empty() );
+ VERIFY( o0.size() == 0 );
+ VERIFY( o0.max_size() == 0 );
+ VERIFY( o0.begin() == o0.end() );
+ VERIFY( Test::ctor == 0 and Test::copy == 0 and Test::dtor == 0 );
+
+ {
+ dynarray<Test> a(5);
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 5 );
+ VERIFY( a.max_size() == 5 );
+ VERIFY( a.begin() != a.end() );
+ VERIFY( Test::ctor == 5 and Test::copy == 0 and Test::dtor == 0 );
+ for(Test &i : a)
+ {
+ VERIFY(i.a == 0);
+ VERIFY(i.b == 0);
+ }
+ }
+ VERIFY( Test::ctor == 5 and Test::copy == 0 and Test::dtor == 5 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/cons/cons.cc b/libstdc++-v3/testsuite/23_containers/dynarray/cons/cons.cc
new file mode 100644
index 0000000..67cd6c8
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/cons/cons.cc
@@ -0,0 +1,71 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+void
+test01()
+{
+ dynarray<int> a(10);
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 10 );
+ VERIFY( a.max_size() == 10 );
+ for(int i : a)
+ VERIFY( i == 0 );
+
+ dynarray<int> b(5, -1);
+ VERIFY( not b.empty() );
+ VERIFY( b.size() == 5 );
+ VERIFY( b.max_size() == 5 );
+ for(int i : b)
+ VERIFY( i == -1 );
+
+ dynarray<int> b_c(b);
+ VERIFY( not b_c.empty() );
+ VERIFY( b_c.size() == 5 );
+ VERIFY( b_c.max_size() == 5 );
+ for(int i : b_c)
+ VERIFY( i == -1 );
+
+ dynarray<int> c{10, 11, 12, 13};
+ VERIFY( not c.empty() );
+ VERIFY( c.size() == 4 );
+ VERIFY( c.max_size() == 4 );
+ int j = 10;
+ for(int i : c)
+ VERIFY( i == j++ );
+
+ dynarray<int> d0(0);
+ VERIFY( d0.empty() );
+ VERIFY( d0.begin() == d0.end() );
+ VERIFY( d0.size() == 0 );
+ VERIFY( d0.max_size() == 0 );
+
+ // TODO allocator
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/data/data.cc b/libstdc++-v3/testsuite/23_containers/dynarray/data/data.cc
new file mode 100644
index 0000000..bc33f17
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/data/data.cc
@@ -0,0 +1,55 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+void
+test01()
+{
+ int a_data[7];
+ std::fill_n(a_data, 7, 0xff);
+
+ dynarray<int> a(7, 0xff);
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 7 );
+ VERIFY( a.data() );
+ VERIFY( std::equal(a.begin(), a.end(), a_data) );
+ VERIFY( std::equal(a.cbegin(), a.cend(), a_data) );
+
+ int b_data[3];
+ std::fill_n(b_data, 3, -2);
+
+ dynarray<int> const b(3, -2);
+ VERIFY( not b.empty() );
+ VERIFY( b.size() == 3);
+ VERIFY( b.data() );
+ VERIFY( std::equal(b.begin(), b.end(), b_data) );
+ VERIFY( std::equal(b.cbegin(), b.cend(), b_data) );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/dynarray_dynarray.cc b/libstdc++-v3/testsuite/23_containers/dynarray/dynarray_dynarray.cc
new file mode 100644
index 0000000..d214168
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/dynarray_dynarray.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+struct X { };
+
+void
+test01()
+{
+ dynarray<dynarray<X>> a(3, dynarray<X>(2));
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 3 );
+ VERIFY( a.max_size() == a.size() );
+ for(dynarray<X> &i : a)
+ {
+ VERIFY( not i.empty() );
+ VERIFY( i.size() == 2 );
+ VERIFY( i.max_size() == i.size() );
+ }
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/mutate/mutate.cc b/libstdc++-v3/testsuite/23_containers/dynarray/mutate/mutate.cc
new file mode 100644
index 0000000..105fc4b
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/mutate/mutate.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+void
+test01()
+{
+ dynarray<int> a(12, 0xffu);
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 12 );
+ VERIFY( a.front() == 0xffu );
+ VERIFY( a.back() == 0xffu );
+ VERIFY( a[2] == 0xffu );
+ for(int i : a)
+ VERIFY(i == 0xffu);
+
+ a.fill(-1);
+ VERIFY( not a.empty() );
+ VERIFY( a.size() == 12 );
+ VERIFY( a.front() == -1 );
+ VERIFY( a.back() == -1 );
+ for(int i : a)
+ VERIFY(i == -1);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/dynarray/riterator.cc b/libstdc++-v3/testsuite/23_containers/dynarray/riterator.cc
new file mode 100644
index 0000000..bf5f229
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/dynarray/riterator.cc
@@ -0,0 +1,56 @@
+// { dg-options "-std=gnu++1y" }
+//
+// Copyright (C) 2013 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/>.
+
+#include <dynarray>
+#include <testsuite_hooks.h>
+
+using std::dynarray;
+
+void
+test01()
+{
+ dynarray<int> a{1, 2, 3, 4, 5};
+ VERIFY( a.front() == 1 );
+ VERIFY( a.back() == 5 );
+ int j = 5;
+ for(dynarray<int>::reverse_iterator i = a.rbegin();
+ i != a.rend();
+ ++i)
+ VERIFY( *i == j-- );
+
+ j = 5;
+ for(dynarray<int>::const_reverse_iterator i = a.crbegin();
+ i != a.crend();
+ ++i)
+ VERIFY( *i == j-- );
+
+ dynarray<int> const &b = a;
+ j = 5;
+ for(dynarray<int>::const_reverse_iterator i = b.rbegin();
+ i != b.rend();
+ ++i)
+ VERIFY( *i == j-- );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
--
1.8.4