Commit 95e9a761 by JeanHeyd Meneide Committed by Jonathan Wakely

Implement std::span for C++20

2019-09-05  JeanHeyd Meneide  <phdofthehouse@gmail.com>

	* include/Makefile.am: Add <span> header.
	* include/Makefile.in: Regenerate.
	* include/bits/range_access.h (__adl_begin, __adl_end, __adl_cbegin)
	(__adl_cend, __adl_rbegin, __adl_rend, __adl_crbegin, __adl_crend)
	(__adl_data, __adl_cdata, __adl_size, __adl_empty, __adl_to_address):
	New functions for performing argument-dependent lookup of range
	customization points.
	* include/bits/stl_iterator.h (__normal_iterator): Add
	_GLIBCXX20_CONSTEXPR to all functions.
	* include/std/span: New header.
	* include/std/version (__cpp_lib_span): Define feature test macro.
	* testsuite/23_containers/span/contiguous_range_neg.cc: New test.
	* testsuite/23_containers/span/everything.cc: New test.
	* testsuite/23_containers/span/get_neg.cc: New test.
	* testsuite/23_containers/span/last_neg.cc: New test.
	* testsuite/23_containers/span/subspan_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_dynamic_neg.cc: New test.
	* testsuite/23_containers/span/tuple_element_oob_neg.cc: New test.
	* testsuite/23_containers/span/tuple_size_neg.cc: New test.

From-SVN: r275403
parent 056f95ec
2019-09-05 JeanHeyd Meneide <phdofthehouse@gmail.com>
* include/Makefile.am: Add <span> header.
* include/Makefile.in: Regenerate.
* include/bits/range_access.h (__adl_begin, __adl_end, __adl_cbegin)
(__adl_cend, __adl_rbegin, __adl_rend, __adl_crbegin, __adl_crend)
(__adl_data, __adl_cdata, __adl_size, __adl_empty, __adl_to_address):
New functions for performing argument-dependent lookup of range
customization points.
* include/bits/stl_iterator.h (__normal_iterator): Add
_GLIBCXX20_CONSTEXPR to all functions.
* include/std/span: New header.
* include/std/version (__cpp_lib_span): Define feature test macro.
* testsuite/23_containers/span/contiguous_range_neg.cc: New test.
* testsuite/23_containers/span/everything.cc: New test.
* testsuite/23_containers/span/get_neg.cc: New test.
* testsuite/23_containers/span/last_neg.cc: New test.
* testsuite/23_containers/span/subspan_neg.cc: New test.
* testsuite/23_containers/span/tuple_element_dynamic_neg.cc: New test.
* testsuite/23_containers/span/tuple_element_oob_neg.cc: New test.
* testsuite/23_containers/span/tuple_size_neg.cc: New test.
2019-09-05 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/manual/allocator.xml: Remove URL for bibliography entry.
......
......@@ -68,6 +68,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
......
......@@ -412,6 +412,7 @@ std_headers = \
${std_srcdir}/scoped_allocator \
${std_srcdir}/set \
${std_srcdir}/shared_mutex \
${std_srcdir}/span \
${std_srcdir}/sstream \
${std_srcdir}/stack \
${std_srcdir}/stdexcept \
......
......@@ -318,6 +318,78 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // C++17
#if __cplusplus > 201703L
// "why are these in namespace std:: and not __gnu_cxx:: ?"
// because if we don't put them here it's impossible to
// have implicit ADL with "using std::begin/end/size/data;".
template <typename _Container>
constexpr auto
__adl_begin(_Container& __cont) noexcept(noexcept(begin(__cont)))
{ return begin(__cont); }
template <typename _Container>
constexpr auto
__adl_end(_Container& __cont) noexcept(noexcept(end(__cont)))
{ return end(__cont); }
template <typename _Container>
constexpr auto
__adl_cbegin(_Container& __cont) noexcept(noexcept(cbegin(__cont)))
{ return cbegin(__cont); }
template <typename _Container>
constexpr auto
__adl_cend(_Container& __cont) noexcept(noexcept(cend(__cont)))
{ return cend(__cont); }
template <typename _Container>
constexpr auto
__adl_rbegin(_Container& __cont) noexcept(noexcept(rbegin(__cont)))
{ return rbegin(__cont); }
template <typename _Container>
constexpr auto
__adl_rend(_Container& __cont) noexcept(noexcept(rend(__cont)))
{ return rend(__cont); }
template <typename _Container>
constexpr auto
__adl_crbegin(_Container& __cont) noexcept(noexcept(crbegin(__cont)))
{ return crbegin(__cont); }
template <typename _Container>
constexpr auto
__adl_crend(_Container& __cont) noexcept(noexcept(crend(__cont)))
{ return crend(__cont); }
template <typename _Container>
constexpr auto
__adl_data(_Container& __cont) noexcept(noexcept(data(__cont)))
{ return data(__cont); }
template <typename _Container>
constexpr auto
__adl_cdata(_Container& __cont) noexcept(noexcept(cdata(__cont)))
{ return cdata(__cont); }
template <typename _Container>
constexpr auto
__adl_size(_Container& __cont) noexcept(noexcept(size(__cont)))
{ return size(__cont); }
template <typename _Container>
constexpr auto
__adl_empty(_Container& __cont) noexcept(noexcept(empty(__cont)))
{ return empty(__cont); }
#if defined(_GLIBCXX_P1394) && _GLIBCXX_P1394
template <typename _Container>
constexpr auto
__adl_to_address(_Container& __cont) noexcept(noexcept(to_address(__cont)))
{ return to_address(__cont); }
#endif // P1394 and new contiguous_iterator requirements [iterator.concept.contiguous]
#endif // C++20
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
......
......@@ -446,7 +446,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
template<typename _Iterator>
_GLIBCXX20_CONSTEXPR auto
_GLIBCXX20_CONSTEXPR
auto
__niter_base(reverse_iterator<_Iterator> __it)
-> decltype(__make_reverse_iterator(__niter_base(__it.base())))
{ return __make_reverse_iterator(__niter_base(__it.base())); }
......@@ -457,7 +458,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ };
template<typename _Iterator>
_GLIBCXX20_CONSTEXPR auto
_GLIBCXX20_CONSTEXPR
auto
__miter_base(reverse_iterator<_Iterator> __it)
-> decltype(__make_reverse_iterator(__miter_base(__it.base())))
{ return __make_reverse_iterator(__miter_base(__it.base())); }
......@@ -802,12 +804,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_CONSTEXPR __normal_iterator() _GLIBCXX_NOEXCEPT
: _M_current(_Iterator()) { }
explicit
explicit _GLIBCXX20_CONSTEXPR
__normal_iterator(const _Iterator& __i) _GLIBCXX_NOEXCEPT
: _M_current(__i) { }
// Allow iterator to const_iterator conversion
template<typename _Iter>
_GLIBCXX20_CONSTEXPR
__normal_iterator(const __normal_iterator<_Iter,
typename __enable_if<
(std::__are_same<_Iter, typename _Container::pointer>::__value),
......@@ -815,14 +818,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: _M_current(__i.base()) { }
// Forward iterator requirements
_GLIBCXX20_CONSTEXPR
reference
operator*() const _GLIBCXX_NOEXCEPT
{ return *_M_current; }
_GLIBCXX20_CONSTEXPR
pointer
operator->() const _GLIBCXX_NOEXCEPT
{ return _M_current; }
_GLIBCXX20_CONSTEXPR
__normal_iterator&
operator++() _GLIBCXX_NOEXCEPT
{
......@@ -830,11 +836,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
}
_GLIBCXX20_CONSTEXPR
__normal_iterator
operator++(int) _GLIBCXX_NOEXCEPT
{ return __normal_iterator(_M_current++); }
// Bidirectional iterator requirements
_GLIBCXX20_CONSTEXPR
__normal_iterator&
operator--() _GLIBCXX_NOEXCEPT
{
......@@ -842,31 +850,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return *this;
}
_GLIBCXX20_CONSTEXPR
__normal_iterator
operator--(int) _GLIBCXX_NOEXCEPT
{ return __normal_iterator(_M_current--); }
// Random access iterator requirements
_GLIBCXX20_CONSTEXPR
reference
operator[](difference_type __n) const _GLIBCXX_NOEXCEPT
{ return _M_current[__n]; }
_GLIBCXX20_CONSTEXPR
__normal_iterator&
operator+=(difference_type __n) _GLIBCXX_NOEXCEPT
{ _M_current += __n; return *this; }
_GLIBCXX20_CONSTEXPR
__normal_iterator
operator+(difference_type __n) const _GLIBCXX_NOEXCEPT
{ return __normal_iterator(_M_current + __n); }
_GLIBCXX20_CONSTEXPR
__normal_iterator&
operator-=(difference_type __n) _GLIBCXX_NOEXCEPT
{ _M_current -= __n; return *this; }
_GLIBCXX20_CONSTEXPR
__normal_iterator
operator-(difference_type __n) const _GLIBCXX_NOEXCEPT
{ return __normal_iterator(_M_current - __n); }
_GLIBCXX20_CONSTEXPR
const _Iterator&
base() const _GLIBCXX_NOEXCEPT
{ return _M_current; }
......@@ -882,6 +897,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Forward iterator requirements
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -889,6 +905,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() == __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -896,6 +913,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() == __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -903,6 +921,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() != __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -911,6 +930,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Random access iterator requirements
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -918,6 +938,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() < __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -925,6 +946,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() < __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -932,6 +954,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() > __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -939,6 +962,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() > __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -946,6 +970,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() <= __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -953,6 +978,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() <= __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs)
......@@ -960,6 +986,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() >= __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline bool
operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -973,6 +1000,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _IteratorL, typename _IteratorR, typename _Container>
#if __cplusplus >= 201103L
// DR 685.
_GLIBCXX20_CONSTEXPR
inline auto
operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) noexcept
......@@ -985,6 +1013,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() - __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline typename __normal_iterator<_Iterator, _Container>::difference_type
operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs)
......@@ -992,6 +1021,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __lhs.base() - __rhs.base(); }
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
inline __normal_iterator<_Iterator, _Container>
operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
__n, const __normal_iterator<_Iterator, _Container>& __i)
......@@ -1006,6 +1036,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Iterator, typename _Container>
_GLIBCXX20_CONSTEXPR
_Iterator
__niter_base(__gnu_cxx::__normal_iterator<_Iterator, _Container> __it)
_GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
......
......@@ -167,6 +167,9 @@
#define __cpp_lib_list_remove_return_type 201806L
#define __cpp_lib_math_constants 201907L
#define __cpp_lib_to_array 201907L
// FIXME: they forgot this feature test macro
// get on someone's back about it in Belfast!!!
#define __cpp_lib_span 201911
#endif // C++2a
#endif // C++17
#endif // C++14
......
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
#include <deque>
int
main()
{
std::deque<int> d{};
std::span<int, std::dynamic_extent> myspan(d); // { dg-error "no match" }
}
// { dg-prune-output "data" }
// { dg-prune-output "invalid operands" }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do run { target c++2a } }
#include <testsuite_hooks.h>
#include <span>
#include <type_traits>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <cassert>
int
main()
{
struct alignas(256) strawman
{
int x;
int y;
bool z;
int w;
};
struct naked_span
{
char* p;
std::size_t n;
};
struct strawman_span
{
strawman* p;
std::size_t n;
};
static_assert(sizeof(std::span<char, 0>) <= sizeof(char*));
static_assert(sizeof(std::span<const char, 0>) <= sizeof(const char*));
static_assert(sizeof(std::span<strawman, 0>) <= sizeof(strawman*));
static_assert(sizeof(std::span<strawman, 1>) <= sizeof(strawman*));
static_assert(sizeof(std::span<char>) <= sizeof(naked_span));
static_assert(sizeof(std::span<strawman>) <= sizeof(strawman_span));
constexpr static std::array<int, 9> arr_data{ 0, 1, 2, 3, 4, 5, 6, 7, 8 };
constexpr auto arr_data_span = std::span(arr_data);
static_assert(arr_data_span.size() == 9);
static_assert(arr_data_span.size_bytes() == 9 * sizeof(int));
static_assert(*arr_data_span.begin() == 0);
static_assert(*arr_data_span.data() == 0);
static_assert(arr_data_span.front() == 0);
static_assert(arr_data_span.back() == 8);
static_assert(arr_data_span[0] == 0);
static_assert(arr_data_span[1] == 1);
static_assert(arr_data_span[2] == 2);
static_assert(arr_data_span[3] == 3);
static_assert(arr_data_span[4] == 4);
static_assert(arr_data_span[5] == 5);
static_assert(arr_data_span[6] == 6);
static_assert(arr_data_span[7] == 7);
static_assert(arr_data_span[8] == 8);
static_assert(!arr_data_span.empty());
static_assert(decltype(arr_data_span)::extent == 9);
constexpr static int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
constexpr auto data_span = std::span(data);
static_assert(data_span.size() == 9);
static_assert(data_span.size_bytes() == 9 * sizeof(int));
static_assert(*data_span.begin() == 0);
static_assert(*data_span.data() == 0);
static_assert(data_span.front() == 0);
static_assert(data_span.back() == 8);
static_assert(data_span[0] == 0);
static_assert(data_span[1] == 1);
static_assert(data_span[2] == 2);
static_assert(data_span[3] == 3);
static_assert(data_span[4] == 4);
static_assert(data_span[5] == 5);
static_assert(data_span[6] == 6);
static_assert(data_span[7] == 7);
static_assert(data_span[8] == 8);
static_assert(!data_span.empty());
static_assert(decltype(data_span)::extent == 9);
constexpr auto data_span_first = data_span.first<3>();
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_first)>, std::span<const int, 3>>);
static_assert(decltype(data_span_first)::extent == 3);
static_assert(data_span_first.size() == 3);
static_assert(data_span_first.front() == 0);
static_assert(data_span_first.back() == 2);
static_assert(std::tuple_size_v<decltype(data_span_first)> == 3);
static_assert(std::is_same_v<std::tuple_element_t<0, decltype(data_span_first)>, const int>);
constexpr auto data_span_first_dyn = data_span.first(4);
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_first_dyn)>, std::span<const int>>);
static_assert(decltype(data_span_first_dyn)::extent == std::dynamic_extent);
static_assert(data_span_first_dyn.size() == 4);
static_assert(data_span_first_dyn.front() == 0);
static_assert(data_span_first_dyn.back() == 3);
constexpr auto data_span_last = data_span.last<5>();
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_last)>, std::span<const int, 5>>);
static_assert(decltype(data_span_last)::extent == 5);
static_assert(data_span_last.size() == 5);
static_assert(data_span_last.front() == 4);
static_assert(data_span_last.back() == 8);
static_assert(std::tuple_size_v<decltype(data_span_last)> == 5);
static_assert(std::is_same_v<std::tuple_element_t<0, decltype(data_span_last)>, const int>);
constexpr auto data_span_last_dyn = data_span.last(6);
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_last_dyn)>, std::span<const int>>);
static_assert(decltype(data_span_last_dyn)::extent == std::dynamic_extent);
static_assert(data_span_last_dyn.size() == 6);
static_assert(data_span_last_dyn.front() == 3);
static_assert(data_span_last_dyn.back() == 8);
constexpr auto data_span_subspan = data_span.subspan<1, 3>();
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_subspan)>, std::span<const int, 3>>);
static_assert(decltype(data_span_subspan)::extent == 3);
static_assert(data_span_subspan.size() == 3);
static_assert(data_span_subspan.front() == 1);
static_assert(data_span_subspan.back() == 3);
constexpr auto data_span_subspan_offset = data_span.subspan<8>();
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_subspan_offset)>, std::span<const int, 1>>);
static_assert(decltype(data_span_subspan_offset)::extent == 1);
static_assert(data_span_subspan_offset.size() == 1);
static_assert(data_span_subspan_offset.front() == 8);
static_assert(data_span_subspan_offset.back() == 8);
constexpr auto data_span_subspan_empty = data_span.subspan(9, 0);
static_assert(
std::is_same_v<std::remove_cv_t<decltype(data_span_subspan_empty)>, std::span<const int>>);
static_assert(decltype(data_span_subspan_empty)::extent == std::dynamic_extent);
static_assert(data_span_subspan_empty.size() == 0);
constexpr auto data_span_subspan_empty_static = data_span.subspan<9>();
static_assert(std::is_same_v<std::remove_cv_t<decltype(data_span_subspan_empty_static)>,
std::span<const int, 0>>);
static_assert(decltype(data_span_subspan_empty_static)::extent == 0);
static_assert(data_span_subspan_empty.size() == 0);
std::span<short> shorts{};
bool really_empty0 = shorts.empty();
bool really_empty1 = std::empty(shorts);
bool really_empty2 = shorts.data() == nullptr;
bool really_empty3 = shorts.begin() == shorts.end();
bool really_empty4 = shorts.cbegin() == shorts.cend();
bool really_empty =
really_empty0 && really_empty1 && really_empty2 && really_empty3 && really_empty4;
(void)really_empty;
VERIFY(really_empty);
std::vector<std::int_least32_t> value{ 0 };
std::span<int32_t> muh_span(value);
VERIFY(muh_span.size() == 1);
std::byte* original_bytes = reinterpret_cast<std::byte*>(value.data());
original_bytes[0] = static_cast<std::byte>(1);
original_bytes[1] = static_cast<std::byte>(2);
original_bytes[2] = static_cast<std::byte>(3);
original_bytes[3] = static_cast<std::byte>(4);
std::span<const std::byte> muh_byte_span = std::as_bytes(muh_span);
std::span<std::byte> muh_mutable_byte_span = std::as_writable_bytes(muh_span);
std::span<std::byte> muh_original_byte_span(original_bytes, original_bytes + 4);
bool definitely_reinterpret_casted0 = std::equal(muh_byte_span.cbegin(), muh_byte_span.cend(),
muh_original_byte_span.cbegin(), muh_original_byte_span.cend());
bool definitely_reinterpret_casted1 = std::equal(muh_mutable_byte_span.cbegin(),
muh_mutable_byte_span.cend(), muh_original_byte_span.cbegin(), muh_original_byte_span.cend());
bool definitely_reinterpret_casted =
definitely_reinterpret_casted0 && definitely_reinterpret_casted1;
(void)definitely_reinterpret_casted;
VERIFY(definitely_reinterpret_casted);
std::span<std::byte> muh_original_byte_span_ptr_size(original_bytes, 4);
bool definitely_equivalent =
std::equal(muh_original_byte_span_ptr_size.cbegin(), muh_original_byte_span_ptr_size.cend(),
muh_original_byte_span.cbegin(), muh_original_byte_span.cend());
(void)definitely_equivalent;
VERIFY(definitely_equivalent);
return definitely_equivalent && definitely_reinterpret_casted && really_empty ? 0 : 1;
}
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
#include <tuple>
int
main()
{
std::span<int, std::dynamic_extent> myspan((int*)nullptr, 0ul);
std::get<0>(myspan); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
int
main()
{
std::span<int, 2> myspan(nullptr, 2);
myspan.last<3>(); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
int
main()
{
std::span<int, 2> myspan(nullptr, 2);
myspan.subspan<3, 1>(); // { dg-error "here" }
}
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
#include <tuple>
std::tuple_element<0, std::span<int, std::dynamic_extent>> ts; // { dg-error "here" }
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
#include <tuple>
std::tuple_element<3, std::span<int, 2>> te; // { dg-error "here" }
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
// 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/>.
// { dg-options "-std=c++2a" }
// { dg-do compile { target c++2a } }
#include <span>
#include <tuple>
std::tuple_size<std::span<int, std::dynamic_extent>> ts; // { dg-error "here" }
// { dg-error "static assertion failed" "" { target *-*-* } 0 }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment