]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Implement std::experimental::fundamentals_v2::make_array and std::experimental::funda...
authorVille Voutilainen <ville.voutilainen@gmail.com>
Thu, 13 Aug 2015 14:55:46 +0000 (17:55 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Thu, 13 Aug 2015 14:55:46 +0000 (17:55 +0300)
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

libstdc++-v3/ChangeLog
libstdc++-v3/doc/html/manual/status.html
libstdc++-v3/doc/xml/manual/status_cxx2017.xml
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/experimental/array [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/array/make_array.cc [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/array/neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/array/neg.ii.gz [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/array/neg.s [new file with mode: 0644]

index 13b83da84f71432e41c1b9db1b6670654692ac83..de05109e92c9383ed95a080c585512f35d6b96ce 100644 (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.
index b388ff7fb2ea695bb2e020163d7a24c4381996db..4ec871f1127193a8d9eacc234a97733dba37e608 100644 (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>
\ No newline at end of file
+ </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>
index b62536480aa3ab7571840666b969c70563390579..fc2ebd2466f7d57b37015b07d1a7e19d423a0d99 100644 (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>
 
index c0028dd324e1d172d3e938246bfd16fb5f5c285a..41fc4af6d3067c99844e629e6019f303743047f8 100644 (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 \
index 9539f5fe06238867d7ceb6d5d235a4d081889584..6470d0173d53ee8be75f48288a29790034e5d044 100644 (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 \
diff --git a/libstdc++-v3/include/experimental/array b/libstdc++-v3/include/experimental/array
new file mode 100644 (file)
index 0000000..a6e983a
--- /dev/null
@@ -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
diff --git a/libstdc++-v3/testsuite/experimental/array/make_array.cc b/libstdc++-v3/testsuite/experimental/array/make_array.cc
new file mode 100644 (file)
index 0000000..772ef46
--- /dev/null
@@ -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{});
+}
diff --git a/libstdc++-v3/testsuite/experimental/array/neg.cc b/libstdc++-v3/testsuite/experimental/array/neg.cc
new file mode 100644 (file)
index 0000000..df532d1
--- /dev/null
@@ -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 }
+}
diff --git a/libstdc++-v3/testsuite/experimental/array/neg.ii.gz b/libstdc++-v3/testsuite/experimental/array/neg.ii.gz
new file mode 100644 (file)
index 0000000..8773316
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 (file)
index 0000000..e22209f
--- /dev/null
@@ -0,0 +1 @@
+       .file   "neg.cc"