aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/span
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-12-20 12:09:10 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2025-01-08 12:45:38 +0000
commit5db068738469be8c2bf3cfbda4c54725bd9fe228 (patch)
treef65453eaf6ddcf859ea8aa05a1f54d59bfc2c6cf /libstdc++-v3/include/std/span
parentcbef2c1dbd0a609f68862c0a9aa9bf80a502411e (diff)
downloadgcc-5db068738469be8c2bf3cfbda4c54725bd9fe228.zip
gcc-5db068738469be8c2bf3cfbda4c54725bd9fe228.tar.gz
gcc-5db068738469be8c2bf3cfbda4c54725bd9fe228.tar.bz2
libstdc++: add initializer_list constructor to std::span (P2447R6)
This commit implements P2447R6. The code is straightforward (just one extra constructor, with constraints and conditional explicit). I decided to suppress -Winit-list-lifetime because otherwise it would give too many false positives. The new constructor is meant to be used as a parameter-passing interface (this is a design choice, see P2447R6/ยง2) and, as such, the initializer_list won't dangle despite GCC's warnings. The new constructor isn't 100% backwards compatible. A couple of examples are included in Annex C, but I have also lifted some more from R4. A new test checks for the old and the new behaviors. libstdc++-v3/ChangeLog: * include/bits/version.def: Add the new feature-testing macro. * include/bits/version.h: Regenerate. * include/std/span: Add constructor from initializer_list. * testsuite/23_containers/span/init_list_cons.cc: New test. * testsuite/23_containers/span/init_list_cons_neg.cc: New test. Signed-off-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'libstdc++-v3/include/std/span')
-rw-r--r--libstdc++-v3/include/std/span17
1 files changed, 17 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span
index 4cee890..4b40bd0 100644
--- a/libstdc++-v3/include/std/span
+++ b/libstdc++-v3/include/std/span
@@ -39,6 +39,7 @@
#endif
#define __glibcxx_want_span
+#define __glibcxx_want_span_initializer_list
#include <bits/version.h>
#ifdef __cpp_lib_span // C++ >= 20 && concepts
@@ -46,6 +47,9 @@
#include <cstddef>
#include <bits/stl_iterator.h>
#include <bits/ranges_base.h>
+#ifdef __cpp_lib_span_initializer_list
+# include <initializer_list>
+#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -228,6 +232,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_ptr(ranges::data(__range)), _M_extent(ranges::size(__range))
{ }
+#if __cpp_lib_span_initializer_list >= 202311L // >= C++26
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Winit-list-lifetime"
+ constexpr
+ explicit(extent != dynamic_extent)
+ span(initializer_list<value_type> __il)
+ requires (is_const_v<_Type>)
+ : _M_ptr(__il.begin()), _M_extent(__il.size())
+ {
+ }
+#pragma GCC diagnostic pop
+#endif
+
constexpr
span(const span&) noexcept = default;