RFC - Another step towards dynarray?
Ed Smith-Rowland
3dw4rd@verizon.net
Sun Apr 27 21:05:00 GMT 2014
Greetings,
I had a start on <dynarray> in my tree and started working on it after
stage 1 opened on gcc-4.10.
After googling around I stumbled on the always_inline attribute and
decided to try it. It seems to work.
Anyway, somehow I had forgotten about the conversations about this that
Jonathan and Ruediger had on libstdc++ in the 2013-09 timeframe. So I
stopped work so as not to scoop anyone - I'm sorry if I did.
I would like to offer this incomplete patch (the allocator ctors are
messed up, also there's a DR). I think, assuming I really am right
about [[gny::always_inline]] offering us a way forward. It would be goo
to have someone take that solution and merge it into one of our patches
(I think Jonathan is ahead on the allocator thing). Or work something out.
I'm putting this up for discussion so I didn't put it to gcc-patches.
Regards,
Ed
-------------- next part --------------
2014-04-27 Ed Smith-Rowland <3dw4rd@verizon.net>
Implement C++14 + array TS dynarray.
* include/experimental/dynarray: New.
* include/Makefile.am: Add optional/dynarray.
* include/Makefile.in: Add optional/dynarray.
* testsuite/experimental/dynarray/check_construct_destroy.cc: New.
* testsuite/experimental/dynarray/cons/1.cc: New.
* testsuite/experimental/dynarray/cons/2.cc: New.
* testsuite/experimental/dynarray/cons/3.cc: New.
* testsuite/experimental/dynarray/cons/cons_size.cc: New.
* testsuite/experimental/dynarray/data_access/1.cc: New.
* testsuite/experimental/dynarray/element_access/1.cc: New.
* testsuite/experimental/dynarray/range_access.cc: New.
* testsuite/experimental/dynarray/requirements/explicit_instantiation/:
1.cc: New.
* testsuite/experimental/dynarray/requirements/typedefs.cc: New.
* testsuite/experimental/dynarray/types/1.cc: New.
* testsuite/experimental/dynarray/vec4.cc: New.
-------------- next part --------------
Index: include/experimental/dynarray
===================================================================
--- include/experimental/dynarray (revision 0)
+++ include/experimental/dynarray (working copy)
@@ -0,0 +1,396 @@
+// Components for manipulating sequences of objects where the size is fixed
+// at construction. -*- C++ -*-
+
+// Copyright (C) 2014 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 experimental/dynarray
+ * This is a Standard C++ Library header.
+ */
+
+//
+// N3820 dynarray library
+//
+
+#ifndef _GLIBCXX_EXPERIMENTAL_DYNARRAY
+#define _GLIBCXX_EXPERIMENTAL_DYNARRAY 1
+
+#pragma GCC system_header
+
+#if __cplusplus <= 201103L
+# include <bits/c++14_warning.h>
+#else
+
+#include <stdexcept>
+#include <memory>
+//#include <new> // For bad_array_length
+#include <limits> // For numeric_limits
+
+#define USE_ALLOCA 1
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace experimental
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ template<typename _Tp> // DefaultConstructible _Tp
+ struct dynarray
+ {
+ // types:
+ using value_type = _Tp;
+ using reference = _Tp&;
+ using const_reference = const _Tp&;
+ using pointer = _Tp*;
+ using const_pointer = const _Tp*;
+ using iterator = _Tp*;
+ using const_iterator = const _Tp*;
+ using reverse_iterator = std::reverse_iterator<iterator>;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+ using size_type = size_t;
+ using difference_type = ptrdiff_t;
+
+ private:
+
+ // fields:
+ const size_type _M_size;
+ pointer _M_data;
+
+ // helper functions:
+ void
+ _M_check(size_type __num) const
+ {
+ if (__num >= this->_M_size)
+ std::__throw_out_of_range_fmt(__N("dynarray::at: num (which is %zu) "
+ ">= size() (which is %zu)"),
+ __num, this->_M_size);
+ }
+
+ [[gnu::always_inline]]
+ pointer
+ _M_allocate(size_type __num)
+ {
+ if (__num >= std::numeric_limits<size_type>::max() / sizeof(value_type))
+ throw std::bad_array_length();
+ size_type __size = __num * sizeof(value_type);
+#ifdef USE_ALLOCA
+ return reinterpret_cast<pointer>(alloca(__size));
+#else
+ return reinterpret_cast<pointer>(new char[__size]);
+#endif
+ }
+
+ void
+ _M_deallocate()
+ {
+#ifndef USE_ALLOCA
+ delete[] this->_M_data;
+#endif
+ }
+
+ dynarray() = delete;
+
+ public:
+
+ // construct and destruct:
+ [[gnu::always_inline]]
+ explicit dynarray(size_type __num)
+ : _M_size{__num},
+ _M_data{this->_M_allocate(__num)}
+ { std::__uninitialized_default_n(this->_M_data, this->_M_size); }
+
+ template<typename _Alloc>
+ [[gnu::always_inline]]
+ dynarray(std::allocator_arg_t, const _Alloc& __alloc, size_type __num)
+ : _M_size{__num},
+ _M_data{this->_M_allocate(__num)}
+ {
+ size_type __i;
+ try
+ {
+ for (__i = 0; __i < this->_M_size; ++__i)
+ __alloc.construct(this->_M_data + __i, value_type());
+ }
+ catch (...)
+ {
+ std::_Destroy(this->begin(), this->begin() + __i);
+ __throw_exception_again;
+ }
+ }
+
+ [[gnu::always_inline]]
+ dynarray(size_type __num, const value_type& __val)
+ : _M_size{__num},
+ _M_data{this->_M_allocate(__num)}
+ { std::uninitialized_fill_n(this->_M_data, this->_M_size, __val); }
+
+ template<typename _Alloc>
+ [[gnu::always_inline]]
+ dynarray(std::allocator_arg_t, const _Alloc& __alloc,
+ size_type __num, const _Tp& __val)
+ : _M_size{__num},
+ _M_data{this->_M_allocate(__num)}
+ {
+ size_type __i;
+ try
+ {
+ for (__i = 0; __i < this->_M_size; ++__i)
+ __alloc.construct(this->_M_data + __i, __val);
+ }
+ catch (...)
+ {
+ std::_Destroy(this->begin(), this->begin() + __i);
+ __throw_exception_again;
+ }
+ }
+
+ [[gnu::always_inline]]
+ dynarray(const dynarray& __dyna)
+ : _M_size{__dyna._M_size},
+ _M_data{_M_allocate(__dyna._M_size)}
+ { std::uninitialized_copy(__dyna.begin(), __dyna.end(), this->begin()); }
+
+ template<typename _Alloc>
+ [[gnu::always_inline]]
+ dynarray(std::allocator_arg_t, const _Alloc& __alloc,
+ const dynarray& __dyna)
+ : _M_size{__dyna._M_size},
+ _M_data{_M_allocate(__dyna._M_size)}
+ {
+ size_type __i;
+ try
+ {
+ for (__i = 0; __i < this->_M_size; ++__i)
+ __alloc.construct(this->_M_data + __i, __dyna[__i]);
+ }
+ catch (...)
+ {
+ std::_Destroy(this->begin(), this->begin() + __i);
+ __throw_exception_again;
+ }
+ }
+
+ [[gnu::always_inline]]
+ dynarray(initializer_list<value_type> __il)
+ : _M_size{__il.size()},
+ _M_data{_M_allocate(__il.size())}
+ { std::uninitialized_copy(__il.begin(), __il.end(), this->begin()); }
+
+ template<typename _Alloc>
+ [[gnu::always_inline]]
+ dynarray(std::allocator_arg_t, const _Alloc& __alloc,
+ std::initializer_list<value_type> __il)
+ : _M_size{__il.size()},
+ _M_data{_M_allocate(__il.size())}
+ {
+ size_type __i;
+ try
+ {
+ auto __src = __il.begin();
+ for (size_type __i = 0; __i < this->_M_size; ++__i, ++__src)
+ __alloc.construct(this->_M_data + __i, *__src);
+ }
+ catch (...)
+ {
+ std::_Destroy(this->begin(), this->begin() + __i);
+ __throw_exception_again;
+ }
+ }
+
+ ~dynarray()
+ {
+ std::_Destroy(this->begin(), this->end());
+ _M_deallocate();
+ }
+
+ const dynarray operator=(const dynarray&) = delete;
+
+ // iterators:
+ iterator
+ begin() noexcept
+ { return this->_M_data; }
+
+ const_iterator
+ begin() const noexcept
+ { return this->_M_data; }
+
+ const_iterator
+ cbegin() const noexcept
+ { return this->_M_data; }
+
+ iterator
+ end() noexcept
+ { return this->_M_data + this->_M_size; }
+
+ const_iterator
+ end() const noexcept
+ { return this->_M_data + this->_M_size; }
+
+ const_iterator
+ cend() const noexcept
+ { return this->_M_data + this->_M_size; }
+
+ reverse_iterator
+ rbegin() noexcept
+ { return reverse_iterator(this->end()); }
+
+ const_reverse_iterator
+ rbegin() const noexcept
+ { return const_reverse_iterator(this->end()); }
+
+ 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 const_reverse_iterator(this->begin()); }
+
+ const_reverse_iterator
+ crend() const noexcept
+ { return const_reverse_iterator(this->begin()); }
+
+ // capacity:
+ size_type
+ size() const noexcept
+ { return this->_M_size; }
+
+ size_type
+ max_size() const noexcept
+ { return this->_M_size; }
+
+ bool
+ empty() const noexcept
+ { return this->_M_size == 0; }
+
+ // element access:
+ reference
+ operator[](size_type __n)
+ { return this->_M_data[__n]; }
+
+ const_reference
+ operator[](size_type __n) const
+ { return this->_M_data[__n]; }
+
+ reference
+ front()
+ { return this->_M_data[0]; }
+
+ const_reference
+ front() const
+ { return this->_M_data[0]; }
+
+ reference
+ back()
+ { return this->_M_data[this->_M_size - 1]; }
+
+ const_reference
+ back() const
+ { return this->_M_data[this->_M_size - 1]; }
+
+ const_reference
+ at(size_type __n) const
+ {
+ this->_M_check(__n);
+ return this->_M_data[__n];
+ }
+
+ reference
+ at(size_type __n)
+ {
+ this->_M_check(__n);
+ return this->_M_data[__n];
+ }
+
+ // data access:
+ pointer
+ data() noexcept
+ { return this->_M_data; }
+
+ const_pointer
+ data() const noexcept
+ { return this->_M_data; }
+
+ // mutating member functions:
+ void
+ fill(const value_type& __val)
+ { std::fill(this->begin(), this->end(), __val); }
+ };
+
+ template<typename _Tp>
+ bool
+ operator==(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ {
+ return std::equal(__lhs.begin(), __lhs.end(),
+ __rhs.begin(), __rhs.end());
+ }
+
+ template<typename _Tp>
+ bool
+ operator!=(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ { return !(__lhs == __rhs); }
+
+ template<typename _Tp>
+ bool
+ operator<(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ {
+ return std::lexicographical_compare(__lhs.begin(), __lhs.end(),
+ __rhs.begin(), __rhs.end());
+ }
+
+ template<typename _Tp>
+ bool
+ operator<=(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ { return !(__rhs < __lhs); }
+
+ template<typename _Tp>
+ bool
+ operator>(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ { return __rhs < __lhs; }
+
+ template<typename _Tp>
+ bool
+ operator>=(const dynarray<_Tp>& __lhs,
+ const dynarray<_Tp>& __rhs)
+ { return !(__lhs < __rhs); }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace experimental
+
+ template<typename _Tp, typename _Alloc>
+ struct uses_allocator<experimental::dynarray<_Tp>, _Alloc> : true_type { };
+
+} // namespace std
+
+#endif // __cplusplus <= 201103L
+
+#endif // _GLIBCXX_EXPERIMENTAL_DYNARRAY
+
Index: include/Makefile.am
===================================================================
--- include/Makefile.am (revision 209731)
+++ include/Makefile.am (working copy)
@@ -638,6 +638,7 @@
experimental_srcdir = ${glibcxx_srcdir}/include/experimental
experimental_builddir = ./experimental
experimental_headers = \
+ ${experimental_srcdir}/dynarray \
${experimental_srcdir}/optional \
${experimental_srcdir}/string_view \
${experimental_srcdir}/string_view.tcc
Index: include/Makefile.in
===================================================================
--- include/Makefile.in (revision 209731)
+++ include/Makefile.in (working copy)
@@ -904,6 +904,7 @@
experimental_srcdir = ${glibcxx_srcdir}/include/experimental
experimental_builddir = ./experimental
experimental_headers = \
+ ${experimental_srcdir}/dynarray \
${experimental_srcdir}/optional \
${experimental_srcdir}/string_view \
${experimental_srcdir}/string_view.tcc
Index: testsuite/experimental/dynarray/check_construct_destroy.cc
===================================================================
--- testsuite/experimental/dynarray/check_construct_destroy.cc (revision 0)
+++ testsuite/experimental/dynarray/check_construct_destroy.cc (working copy)
@@ -0,0 +1,43 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_allocator.h>
+
+using namespace __gnu_test;
+
+int
+main()
+{
+ using Container = std::experimental::dynarray<int>;
+ bool ok = true;
+
+ tracker_allocator_counter::reset();
+ {
+ Container c(std::allocator_arg_t(), tracker_allocator<int>(), {2, 4, 1});
+ ok = check_construct_destroy("Construct from init-list", 3, 0) && ok;
+ ok &= (c[0] == 2);
+ ok &= (c[1] == 4);
+ }
+ ok = check_construct_destroy("Construct from init-list", 3, 3) && ok;
+
+ return ok ? 0 : 1;
+}
+
Index: testsuite/experimental/dynarray/cons/1.cc
===================================================================
--- testsuite/experimental/dynarray/cons/1.cc (revision 0)
+++ testsuite/experimental/dynarray/cons/1.cc (working copy)
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ struct A { };
+
+struct B { };
+
+void
+test01()
+{
+ std::experimental::dynarray<A<B>> da01(0);
+ std::experimental::dynarray<A<B>> da02(5);
+ typedef std::experimental::dynarray<A<B>>::size_type size_type;
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/experimental/dynarray/cons/2.cc
===================================================================
--- testsuite/experimental/dynarray/cons/2.cc (revision 0)
+++ testsuite/experimental/dynarray/cons/2.cc (working copy)
@@ -0,0 +1,44 @@
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ struct A { };
+
+struct B { };
+
+template class std::experimental::dynarray<double>;
+template class std::experimental::dynarray<A<B>>;
+
+void
+test02()
+{
+ std::experimental::dynarray<int> da1(5);
+ std::experimental::dynarray<int> da2(da1);
+}
+
+int
+main()
+{
+ test02();
+ return 0;
+}
Index: testsuite/experimental/dynarray/cons/3.cc
===================================================================
--- testsuite/experimental/dynarray/cons/3.cc (revision 0)
+++ testsuite/experimental/dynarray/cons/3.cc (working copy)
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+
+// test range constructors and range-fill constructor
+void
+test03()
+{
+ bool test [[gnu::unused]] = true;
+ const int A[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
+ const int B[]{7, 7, 7, 7, 7};
+ const int N = sizeof(A) / sizeof(int);
+ const int M = sizeof(B) / sizeof(int);
+
+ std::experimental::dynarray<int> da3(N);
+ std::copy(A, A + N, da3.begin());
+ VERIFY(std::equal(da3.begin(), da3.end(), A));
+
+ std::experimental::dynarray<int> da4(da3);
+ VERIFY(std::equal(da4.begin(), da4.end(), A));
+
+ std::experimental::dynarray<int> da5(M, 7);
+ VERIFY(std::equal(da5.begin(), da5.end(), B));
+ VERIFY(std::equal(B, B + M, da5.begin()));
+}
+
+int
+main()
+{
+ test03();
+ return 0;
+}
Index: testsuite/experimental/dynarray/cons/cons_size.cc
===================================================================
--- testsuite/experimental/dynarray/cons/cons_size.cc (revision 0)
+++ testsuite/experimental/dynarray/cons/cons_size.cc (working copy)
@@ -0,0 +1,40 @@
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_hooks.h>
+#include <testsuite_api.h>
+
+void
+test01()
+{
+ bool test [[gnu::unused]] = true;
+
+ std::experimental::dynarray<__gnu_test::NonCopyConstructible> da(1000);
+ VERIFY( std::distance(da.begin(), da.end()) == 1000 );
+ for (auto& it : da)
+ VERIFY( it == -1 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/experimental/dynarray/data_access/1.cc
===================================================================
--- testsuite/experimental/dynarray/data_access/1.cc (revision 0)
+++ testsuite/experimental/dynarray/data_access/1.cc (working copy)
@@ -0,0 +1,52 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test [[gnu::unused]] = true;
+ using dynarray_type = std::experimental::dynarray<int>;
+
+ {
+ const int A[]{0, 1, 2, 3, 4};
+ dynarray_type da{0, 1, 2, 3, 4};
+ VERIFY(da.data() == &da.front());
+ int* pi = da.data();
+ VERIFY(*pi == 0);
+ }
+
+ {
+ const int A[]{4, 3, 2, 1, 0};
+ const dynarray_type cda{4, 3, 2, 1, 0};
+ VERIFY(cda.data() == &cda.front());
+ const int* pci = cda.data();
+ VERIFY(*pci == 4);
+ }
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/experimental/dynarray/element_access/1.cc
===================================================================
--- testsuite/experimental/dynarray/element_access/1.cc (revision 0)
+++ testsuite/experimental/dynarray/element_access/1.cc (working copy)
@@ -0,0 +1,60 @@
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ struct A { };
+
+struct B { };
+
+// http://gcc.gnu.org/ml/libstdc++/2000-09/msg00002.html
+bool
+test01()
+{
+ bool test [[gnu::unused]] = true;
+ std::experimental::dynarray<A<B>> da01(1);
+ std::experimental::dynarray<A<B>> da02(5);
+ using size_type = std::experimental::dynarray<A<B>>::size_type;
+ using reference = std::experimental::dynarray<A<B>>::reference;
+
+ try
+ {
+ reference r01 [[gnu::unused]] = da01.at(6);
+ VERIFY(false); // Should not get here, as exception thrown.
+ }
+ catch(std::out_of_range& err)
+ {
+ VERIFY(true);
+ }
+ catch(...)
+ {
+ VERIFY(false);
+ }
+ return test;
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/experimental/dynarray/range_access.cc
===================================================================
--- testsuite/experimental/dynarray/range_access.cc (revision 0)
+++ testsuite/experimental/dynarray/range_access.cc (working copy)
@@ -0,0 +1,31 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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/>.
+
+// range access [iterator.range]
+
+#include <experimental/dynarray>
+
+void
+test01()
+{
+ std::experimental::dynarray<double> da{1.0, 2.0, 3.0};
+ std::begin(da);
+ std::end(da);
+}
Index: testsuite/experimental/dynarray/requirements/explicit_instantiation/1.cc
===================================================================
--- testsuite/experimental/dynarray/requirements/explicit_instantiation/1.cc (revision 0)
+++ testsuite/experimental/dynarray/requirements/explicit_instantiation/1.cc (working copy)
@@ -0,0 +1,25 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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/>.
+
+// This file tests explicit instantiation of library containers
+
+#include <experimental/dynarray>
+
+template class std::experimental::dynarray<int>;
Index: testsuite/experimental/dynarray/requirements/typedefs.cc
===================================================================
--- testsuite/experimental/dynarray/requirements/typedefs.cc (revision 0)
+++ testsuite/experimental/dynarray/requirements/typedefs.cc (working copy)
@@ -0,0 +1,25 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <testsuite_containers.h>
+#include <experimental/dynarray>
+
+// Check container for required typedefs.
+__gnu_test::types<std::experimental::dynarray<int>> t;
Index: testsuite/experimental/dynarray/types/1.cc
===================================================================
--- testsuite/experimental/dynarray/types/1.cc (revision 0)
+++ testsuite/experimental/dynarray/types/1.cc (working copy)
@@ -0,0 +1,35 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+#include <testsuite_greedy_ops.h>
+
+int main()
+{
+ std::experimental::dynarray<greedy_ops::X> v(5);
+ const std::experimental::dynarray<greedy_ops::X> w(1);
+
+ v[0];
+ w[0];
+ v.size();
+ v.fill(greedy_ops::X());
+
+ return 0;
+}
Index: testsuite/experimental/dynarray/vec4.cc
===================================================================
--- testsuite/experimental/dynarray/vec4.cc (revision 0)
+++ testsuite/experimental/dynarray/vec4.cc (working copy)
@@ -0,0 +1,28 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 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 <experimental/dynarray>
+
+void
+test01()
+{
+ typedef float float4[4];
+ std::experimental::dynarray<float4> xform(4);
+}
More information about the Libstdc++
mailing list