Implement std::experimental::fundamentals_v2::make_array and std::experimental::fundamentals_v2::to_array.

2015-08-13  Ville Voutilainen  <ville.voutilainen@gmail.com>

	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
This commit is contained in:
Ville Voutilainen 2015-08-13 17:55:46 +03:00 committed by Ville Voutilainen
parent db23e4c46f
commit 9638eccd55
10 changed files with 202 additions and 3 deletions

View File

@ -1,3 +1,15 @@
2015-08-13 Ville Voutilainen <ville.voutilainen@gmail.com>
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 <jwakely@redhat.com>
* include/bits/alloc_traits.h: Add feature-test macro.

View File

@ -563,7 +563,7 @@ not in any particular release.
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4391.html" target="_top">
N4391
</a>
</td><td align="left"> <code class="code">make_array</code>, revision 4 </td><td align="left">Y (not committed yet)</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
</td><td align="left"> <code class="code">make_array</code>, revision 4 </td><td align="left">Y</td><td align="left">Library Fundamentals 2 TS</td></tr><tr><td align="left">
<a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf" target="_top">
N4502
</a>
@ -630,4 +630,4 @@ particular release.
</td></tr></tbody></table></div></div><br class="table-break" /></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="intro.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="license.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Part I. 
Introduction
 </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> License</td></tr></table></div></body></html>
 </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> License</td></tr></table></div></body></html>

View File

@ -316,7 +316,7 @@ not in any particular release.
</link>
</entry>
<entry> <code>make_array</code>, revision 4 </entry>
<entry>Y (not committed yet)</entry>
<entry>Y</entry>
<entry>Library Fundamentals 2 TS</entry>
</row>

View File

@ -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 \

View File

@ -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 \

View File

@ -0,0 +1,109 @@
// <experimental/array> -*- 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
// <http://www.gnu.org/licenses/>.
/** @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 <bits/c++14_warning.h>
#else
#include <array>
#include <functional>
#include <experimental/type_traits>
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 <typename _Up>
struct __is_reference_wrapper : false_type
{};
template <typename _Up>
struct __is_reference_wrapper<reference_wrapper<_Up>> : true_type
{};
template <typename _Dest = void, typename... _Types>
constexpr auto
make_array(_Types&&... __t)
-> array<conditional_t<is_void_v<_Dest>,
common_type_t<_Types...>,
_Dest>,
sizeof...(_Types)>
{
static_assert(__or_<
__not_<is_void<_Dest>>,
__and_<__not_<__is_reference_wrapper<decay_t<_Types>>>...>>
::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 <typename _Tp, size_t _Nm, size_t... _Idx>
constexpr array<remove_cv_t<_Tp>, _Nm>
__to_array(_Tp (&__a)[_Nm],
index_sequence<_Idx...>)
{
return {{__a[_Idx]...}};
}
template <typename _Tp, size_t _Nm>
constexpr array<remove_cv_t<_Tp>, _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

View File

@ -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
// <http://www.gnu.org/licenses/>.
#include <experimental/array>
struct MoveOnly
{
MoveOnly() = default;
MoveOnly(MoveOnly&&) = default;
MoveOnly& operator=(MoveOnly&&) = default;
};
int main()
{
char x[42];
std::array<char, 42> y = std::experimental::to_array(x);
std::array<int, 5> z = std::experimental::make_array(1,2,3,4,5);
std::array<long, 3> zz = std::experimental::make_array(1,2L, 3);
std::array<MoveOnly, 1> zzz = std::experimental::make_array(MoveOnly{});
int dummy;
auto good = std::experimental::make_array<
std::reference_wrapper<int>>(std::ref(dummy));
constexpr char x2[42]{};
constexpr std::array<char, 42> y2 = std::experimental::to_array(x2);
constexpr std::array<int, 5> z2 =
std::experimental::make_array(1,2,3,4,5);
constexpr std::array<long, 3> zz2
= std::experimental::make_array(1,2L, 3);
constexpr std::array<MoveOnly, 1> zzz2 = std::experimental::make_array(MoveOnly{});
}

View File

@ -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
// <http://www.gnu.org/licenses/>.
#include <experimental/array>
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 }
}

Binary file not shown.

View File

@ -0,0 +1 @@
.file "neg.cc"