diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 05be8ad..41fc4af 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 \ @@ -657,6 +658,7 @@ experimental_headers = \ ${experimental_srcdir}/memory \ ${experimental_srcdir}/numeric \ ${experimental_srcdir}/optional \ + ${experimental_srcdir}/propagate_const \ ${experimental_srcdir}/ratio \ ${experimental_srcdir}/set \ ${experimental_srcdir}/string \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index bab83b4..b2a140c 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 \ @@ -946,6 +947,7 @@ experimental_headers = \ ${experimental_srcdir}/memory \ ${experimental_srcdir}/numeric \ ${experimental_srcdir}/optional \ + ${experimental_srcdir}/propagate_const \ ${experimental_srcdir}/ratio \ ${experimental_srcdir}/set \ ${experimental_srcdir}/string \ diff --git a/libstdc++-v3/include/experimental/array b/libstdc++-v3/include/experimental/array new file mode 100644 index 0000000..b72895c --- /dev/null +++ b/libstdc++-v3/include/experimental/array @@ -0,0 +1,107 @@ +// -*- 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...>, + _D>, + 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, _N> +__to_array(_Tp (&__a)[_N], + index_sequence<_Idx...>) +{ + return {{__a[_Idx]...}}; +} + +template +constexpr array, _N> to_array(_Tp (&__a)[_N]) +{ + return __to_array(__a, make_index_sequence<_N>{}); +} + + // @} 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 0000000..8456c37 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/array/make_array.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++14" } +// { dg-do run } + +// 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 0000000..643466b --- /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 *-*-* } 75 } +}