From: Ville Voutilainen Date: Thu, 13 Aug 2015 14:55:46 +0000 (+0300) Subject: Implement std::experimental::fundamentals_v2::make_array and std::experimental::funda... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9638eccd55210744734e1d6e0db74b8993c331aa;p=gcc.git Implement std::experimental::fundamentals_v2::make_array and std::experimental::fundamentals_v2::to_array. 2015-08-13 Ville Voutilainen Implement std::experimental::fundamentals_v2::make_array and std::experimental::fundamentals_v2::to_array. * include/Makefile.am: Add array. * include/Makefile.in: Add array. * include/experimental/array: New. * testsuite/experimental/array/make_array.cc: Likewise. * testsuite/experimental/array/neg.cc: Likewise. * doc/html/manual/status.html: Mark make_array as Y. * doc/xml/manual/status_cxx2017.xml: Likewise. From-SVN: r226865 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 13b83da84f7..de05109e92c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2015-08-13 Ville Voutilainen + + Implement std::experimental::fundamentals_v2::make_array and + std::experimental::fundamentals_v2::to_array. + * include/Makefile.am: Add array. + * include/Makefile.in: Add array. + * include/experimental/array: New. + * testsuite/experimental/array/make_array.cc: Likewise. + * testsuite/experimental/array/neg.cc: Likewise. + * doc/html/manual/status.html: Mark make_array as Y. + * doc/xml/manual/status_cxx2017.xml: Likewise. + 2015-08-13 Jonathan Wakely * include/bits/alloc_traits.h: Add feature-test macro. diff --git a/libstdc++-v3/doc/html/manual/status.html b/libstdc++-v3/doc/html/manual/status.html index b388ff7fb2e..4ec871f1127 100644 --- a/libstdc++-v3/doc/html/manual/status.html +++ b/libstdc++-v3/doc/html/manual/status.html @@ -563,7 +563,7 @@ not in any particular release. N4391 - make_array, revision 4 Y (not committed yet)Library Fundamentals 2 TS + make_array, revision 4 YLibrary Fundamentals 2 TS N4502 @@ -630,4 +630,4 @@ particular release.
\ No newline at end of file + Home License diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml index b62536480aa..fc2ebd2466f 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2017.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2017.xml @@ -316,7 +316,7 @@ not in any particular release. make_array, revision 4 - Y (not committed yet) + Y Library Fundamentals 2 TS diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index c0028dd324e..41fc4af6d30 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -646,6 +646,7 @@ experimental_builddir = ./experimental experimental_headers = \ ${experimental_srcdir}/algorithm \ ${experimental_srcdir}/any \ + ${experimental_srcdir}/array \ ${experimental_srcdir}/chrono \ ${experimental_srcdir}/deque \ ${experimental_srcdir}/erase_if.h \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 9539f5fe062..6470d0173d5 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -935,6 +935,7 @@ experimental_builddir = ./experimental experimental_headers = \ ${experimental_srcdir}/algorithm \ ${experimental_srcdir}/any \ + ${experimental_srcdir}/array \ ${experimental_srcdir}/chrono \ ${experimental_srcdir}/deque \ ${experimental_srcdir}/erase_if.h \ diff --git a/libstdc++-v3/include/experimental/array b/libstdc++-v3/include/experimental/array new file mode 100644 index 00000000000..a6e983aeedf --- /dev/null +++ b/libstdc++-v3/include/experimental/array @@ -0,0 +1,109 @@ +// -*- C++ -*- + +// Copyright (C) 2015 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 +// . + +/** @file experimental/array + * This is a TS C++ Library header. + */ + +#ifndef _GLIBCXX_EXPERIMENTAL_ARRAY +#define _GLIBCXX_EXPERIMENTAL_ARRAY 1 + +#pragma GCC system_header + +#if __cplusplus <= 201103L +# include +#else + +#include +#include +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace experimental +{ +inline namespace fundamentals_v2 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @defgroup make_array Array creation functions + * @ingroup experimental + * + * Array creation functions as described in N4529, + * Working Draft, C++ Extensions for Library Fundamentals, Version 2 + * + * @{ + */ + +template + struct __is_reference_wrapper : false_type + {}; + +template + struct __is_reference_wrapper> : true_type + {}; + +template + constexpr auto + make_array(_Types&&... __t) + -> array, + common_type_t<_Types...>, + _Dest>, + sizeof...(_Types)> + { + static_assert(__or_< + __not_>, + __and_<__not_<__is_reference_wrapper>>...>> + ::value, + "make_array cannot be used without an explicit target type " + "if any of the types given is a reference_wrapper"); + return {{forward<_Types>(__t)...}}; + } + +template + constexpr array, _Nm> + __to_array(_Tp (&__a)[_Nm], + index_sequence<_Idx...>) + { + return {{__a[_Idx]...}}; + } + +template + constexpr array, _Nm> + to_array(_Tp (&__a)[_Nm]) + { + return __to_array(__a, make_index_sequence<_Nm>{}); + } + + // @} group make_array + _GLIBCXX_END_NAMESPACE_VERSION +} // namespace fundamentals_v2 +} // namespace experimental + +} // namespace std + +#endif // C++14 + +#endif // _GLIBCXX_EXPERIMENTAL_ARRAY diff --git a/libstdc++-v3/testsuite/experimental/array/make_array.cc b/libstdc++-v3/testsuite/experimental/array/make_array.cc new file mode 100644 index 00000000000..772ef466ab9 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/make_array.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2015 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +struct MoveOnly +{ + MoveOnly() = default; + MoveOnly(MoveOnly&&) = default; + MoveOnly& operator=(MoveOnly&&) = default; +}; + +int main() +{ + char x[42]; + std::array y = std::experimental::to_array(x); + std::array z = std::experimental::make_array(1,2,3,4,5); + std::array zz = std::experimental::make_array(1,2L, 3); + std::array zzz = std::experimental::make_array(MoveOnly{}); + int dummy; + auto good = std::experimental::make_array< + std::reference_wrapper>(std::ref(dummy)); + constexpr char x2[42]{}; + constexpr std::array y2 = std::experimental::to_array(x2); + constexpr std::array z2 = + std::experimental::make_array(1,2,3,4,5); + constexpr std::array zz2 + = std::experimental::make_array(1,2L, 3); + constexpr std::array zzz2 = std::experimental::make_array(MoveOnly{}); +} diff --git a/libstdc++-v3/testsuite/experimental/array/neg.cc b/libstdc++-v3/testsuite/experimental/array/neg.cc new file mode 100644 index 00000000000..df532d166c5 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/neg.cc @@ -0,0 +1,28 @@ +// { dg-options "-std=gnu++14" } +// { dg-do compile } + +// Copyright (C) 2015 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include + +int main() +{ + int dummy; + auto bad = std::experimental::make_array(std::ref(dummy)); + // { dg-error "make_array cannot be used without an explicit target type if any of the types given is a reference_wrapper" "" { target *-*-* } 76 } +} diff --git a/libstdc++-v3/testsuite/experimental/array/neg.ii.gz b/libstdc++-v3/testsuite/experimental/array/neg.ii.gz new file mode 100644 index 00000000000..8773316ce75 Binary files /dev/null and b/libstdc++-v3/testsuite/experimental/array/neg.ii.gz differ diff --git a/libstdc++-v3/testsuite/experimental/array/neg.s b/libstdc++-v3/testsuite/experimental/array/neg.s new file mode 100644 index 00000000000..e22209f5fe7 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/neg.s @@ -0,0 +1 @@ + .file "neg.cc"