public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* Implement the <array> part of C++20 p1032 Misc constexpr bits.
@ 2019-11-09  1:15 Smith-Rowland, Edward M
  2019-11-14 15:53 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Smith-Rowland, Edward M @ 2019-11-09  1:15 UTC (permalink / raw)
  To: libstdc++, jwakely; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 110 bytes --]

I'm going to implement p1032 in pieces.  It *is* miscellaneous after all ;-).

Tested on x96_64-linux? OK?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: p1032_array.CL --]
[-- Type: text/x-opencl-src; name="p1032_array.CL", Size: 311 bytes --]

2019-11-09  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement the <array> part of C++20 p1032 Misc constexpr bits.
	* include/std/array (fill, swap): Make constexpr.
	* testsuite/23_containers/array/requirements/constexpr_fill.cc: New.
	* testsuite/23_containers/array/requirements/constexpr_swap.cc: New.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: p1032_array.patch --]
[-- Type: text/x-patch; name="p1032_array.patch", Size: 3944 bytes --]

Index: include/std/array
===================================================================
--- include/std/array	(revision 277944)
+++ include/std/array	(working copy)
@@ -112,11 +112,11 @@
       // No explicit construct/copy/destroy for aggregate type.
 
       // DR 776.
-      void
+      _GLIBCXX20_CONSTEXPR void
       fill(const value_type& __u)
       { std::fill_n(begin(), size(), __u); }
 
-      void
+      _GLIBCXX20_CONSTEXPR void
       swap(array& __other)
       noexcept(_AT_Type::_Is_nothrow_swappable::value)
       { std::swap_ranges(begin(), end(), __other.begin()); }
@@ -288,6 +288,7 @@
 
   // Specialized algorithms.
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline
 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
     // Constrained free swap overload, see p0185r1
@@ -295,7 +296,6 @@
       _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::_Is_swappable::value
     >::type
 #else
-    _GLIBCXX20_CONSTEXPR
     void
 #endif
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
Index: testsuite/23_containers/array/requirements/constexpr_fill.cc
===================================================================
--- testsuite/23_containers/array/requirements/constexpr_fill.cc	(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_fill.cc	(working copy)
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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 <array>
+
+constexpr bool
+test_array()
+{
+  auto ok = true;
+
+  std::array<float,3> fa{};
+  fa.fill(3.333f);
+
+  ok = ok && (fa[0] == fa[2]);
+
+  return ok;
+}
+
+static_assert(test_array());
Index: testsuite/23_containers/array/requirements/constexpr_swap.cc
===================================================================
--- testsuite/23_containers/array/requirements/constexpr_swap.cc	(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_swap.cc	(working copy)
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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 <array>
+
+constexpr bool
+test_array()
+{
+  auto ok = true;
+
+  std::array<float,3> fa{{1.1f, 2.2f, 3.3f}};
+
+  std::array<float,3> fb{{4.4f, 5.5f, 6.6f}};
+
+  fb.swap(fa);
+
+  ok = ok && (fa[0] == 4.4f);
+
+  std::swap(fa, fb);
+
+  ok = ok && (fa[0] == 1.1f);
+
+  return ok;
+}
+
+static_assert(test_array());

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Implement the <array> part of C++20 p1032 Misc constexpr bits.
  2019-11-09  1:15 Implement the <array> part of C++20 p1032 Misc constexpr bits Smith-Rowland, Edward M
@ 2019-11-14 15:53 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-11-14 15:53 UTC (permalink / raw)
  To: Smith-Rowland, Edward M; +Cc: libstdc++, gcc-patches

On 09/11/19 01:15 +0000, Smith-Rowland, Edward M wrote:
>I'm going to implement p1032 in pieces.  It *is* miscellaneous after all ;-).
>
>Tested on x96_64-linux? OK?

>2019-11-09  Edward Smith-Rowland  <3dw4rd@verizon.net>
>
>	Implement the <array> part of C++20 p1032 Misc constexpr bits.
>	* include/std/array (fill, swap): Make constexpr.
>	* testsuite/23_containers/array/requirements/constexpr_fill.cc: New.
>	* testsuite/23_containers/array/requirements/constexpr_swap.cc: New.

OK for trunk, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-14 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-09  1:15 Implement the <array> part of C++20 p1032 Misc constexpr bits Smith-Rowland, Edward M
2019-11-14 15:53 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).