diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-10-28 12:07:40 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-10-28 12:07:40 +0000 |
commit | 0f7cd5e5735e5536bf7bc8ca2b998f7ce8b4ddee (patch) | |
tree | 0b9a3fbfdaa07c4791c439c3cd5a87f352f6105d /libstdc++-v3/include/std/span | |
parent | 292c812a27c3a0d53b3689a9cdd0d2acfe17531b (diff) | |
download | gcc-0f7cd5e5735e5536bf7bc8ca2b998f7ce8b4ddee.zip gcc-0f7cd5e5735e5536bf7bc8ca2b998f7ce8b4ddee.tar.gz gcc-0f7cd5e5735e5536bf7bc8ca2b998f7ce8b4ddee.tar.bz2 |
libstdc++: Make std::span layout-compatible with struct iovec [PR 95609]
This change reorders the data members of std::span so that span<byte> is
layout-compatible with common implementations of struct iovec. This will
allow span<byte> to be used directly in places that use a struct iovec
to do scatter-gather I/O.
It's important to note that POSIX doesn't specify the order of members
in iovec. Also the equivalent type on Windows has members in the other
order, and uses type ULONG (which is always 32-bit whereas size_t is
64-bit for Win64). So this change will only help for certain targets and
an indirection between std::span and I/O system calls will still be
needed for the general case.
libstdc++-v3/ChangeLog:
PR libstdc++/95609
* include/std/span (span): Reorder data members to match common
implementations of struct iovec.
* testsuite/23_containers/span/layout_compat.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/std/span')
-rw-r--r-- | libstdc++-v3/include/std/span | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index fb34940..24c61ba 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -38,8 +38,8 @@ #if __cplusplus > 201703L -#include <type_traits> #include <array> +#include <cstddef> #include <bits/stl_iterator.h> #include <bits/ranges_base.h> @@ -151,7 +151,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr span() noexcept requires ((_Extent + 1u) <= 1u) - : _M_extent(0), _M_ptr(nullptr) + : _M_ptr(nullptr), _M_extent(0) { } template<contiguous_iterator _It> @@ -159,7 +159,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr explicit(extent != dynamic_extent) span(_It __first, size_type __count) noexcept - : _M_extent(__count), _M_ptr(std::to_address(__first)) + : _M_ptr(std::to_address(__first)), _M_extent(__count) { if constexpr (_Extent != dynamic_extent) { @@ -173,8 +173,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr explicit(extent != dynamic_extent) span(_It __first, _End __last) noexcept(noexcept(__last - __first)) - : _M_extent(static_cast<size_type>(__last - __first)), - _M_ptr(std::to_address(__first)) + : _M_ptr(std::to_address(__first)), + _M_extent(static_cast<size_type>(__last - __first)) { if constexpr (_Extent != dynamic_extent) { @@ -392,8 +392,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: - [[no_unique_address]] __detail::__extent_storage<extent> _M_extent; pointer _M_ptr; + [[no_unique_address]] __detail::__extent_storage<extent> _M_extent; }; // deduction guides |