2018-07-24 11:01:02 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-07-24 11:01:02 +08:00
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-07-24 11:01:02 +08:00
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_SPAN
|
|
|
|
#define _LIBCPP_SPAN
|
|
|
|
|
|
|
|
/*
|
|
|
|
span synopsis
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
// constants
|
2019-02-27 08:32:16 +08:00
|
|
|
inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
// [views.span], class template span
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class ElementType, size_t Extent = dynamic_extent>
|
2018-07-24 11:01:02 +08:00
|
|
|
class span;
|
|
|
|
|
2021-05-14 14:20:07 +08:00
|
|
|
template<class ElementType, size_t Extent>
|
|
|
|
inline constexpr bool ranges::enable_view<span<ElementType, Extent>> = true;
|
|
|
|
|
2020-11-25 01:08:02 +08:00
|
|
|
template<class ElementType, size_t Extent>
|
|
|
|
inline constexpr bool ranges::enable_borrowed_range<span<ElementType, Extent>> = true;
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
// [span.objectrep], views of object representation
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class ElementType, size_t Extent>
|
2018-08-04 06:36:53 +08:00
|
|
|
span<const byte, ((Extent == dynamic_extent) ? dynamic_extent :
|
2019-03-06 11:59:44 +08:00
|
|
|
(sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class ElementType, size_t Extent>
|
2018-08-04 06:36:53 +08:00
|
|
|
span< byte, ((Extent == dynamic_extent) ? dynamic_extent :
|
2019-03-06 11:59:44 +08:00
|
|
|
(sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class ElementType, size_t Extent = dynamic_extent>
|
2018-07-24 11:01:02 +08:00
|
|
|
class span {
|
|
|
|
public:
|
|
|
|
// constants and types
|
|
|
|
using element_type = ElementType;
|
|
|
|
using value_type = remove_cv_t<ElementType>;
|
2019-11-14 22:07:05 +08:00
|
|
|
using size_type = size_t;
|
2018-07-24 11:01:02 +08:00
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = element_type*;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_pointer = const element_type*;
|
2018-07-24 11:01:02 +08:00
|
|
|
using reference = element_type&;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_reference = const element_type&;
|
2019-02-27 08:32:16 +08:00
|
|
|
using iterator = implementation-defined;
|
2018-07-24 11:01:02 +08:00
|
|
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
2019-11-14 22:07:05 +08:00
|
|
|
static constexpr size_type extent = Extent;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
// [span.cons], span constructors, copy, assignment, and destructor
|
|
|
|
constexpr span() noexcept;
|
2021-10-09 04:57:44 +08:00
|
|
|
template <class It>
|
|
|
|
constexpr explicit(Extent != dynamic_extent) span(It first, size_type count);
|
|
|
|
template <class It, class End>
|
|
|
|
constexpr explicit(Extent != dynamic_extent) span(It first, End last);
|
2018-07-24 11:01:02 +08:00
|
|
|
template <size_t N>
|
2021-10-15 05:02:43 +08:00
|
|
|
constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
|
2018-07-24 11:01:02 +08:00
|
|
|
template <size_t N>
|
|
|
|
constexpr span(array<value_type, N>& arr) noexcept;
|
|
|
|
template <size_t N>
|
|
|
|
constexpr span(const array<value_type, N>& arr) noexcept;
|
2021-10-09 04:57:44 +08:00
|
|
|
template<class R>
|
|
|
|
constexpr explicit(Extent != dynamic_extent) span(R&& r);
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span(const span& other) noexcept = default;
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class OtherElementType, size_t OtherExtent>
|
2020-05-13 21:50:06 +08:00
|
|
|
constexpr explicit(Extent != dynamic_extent) span(const span<OtherElementType, OtherExtent>& s) noexcept;
|
2018-07-24 11:01:02 +08:00
|
|
|
~span() noexcept = default;
|
|
|
|
constexpr span& operator=(const span& other) noexcept = default;
|
|
|
|
|
|
|
|
// [span.sub], span subviews
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t Count>
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span<element_type, Count> first() const;
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t Count>
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span<element_type, Count> last() const;
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t Offset, size_t Count = dynamic_extent>
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span<element_type, see below> subspan() const;
|
|
|
|
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr span<element_type, dynamic_extent> first(size_type count) const;
|
|
|
|
constexpr span<element_type, dynamic_extent> last(size_type count) const;
|
|
|
|
constexpr span<element_type, dynamic_extent> subspan(size_type offset, size_type count = dynamic_extent) const;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
// [span.obs], span observers
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr size_type size() const noexcept;
|
|
|
|
constexpr size_type size_bytes() const noexcept;
|
2021-10-13 10:30:58 +08:00
|
|
|
[[nodiscard]] constexpr bool empty() const noexcept;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
// [span.elem], span element access
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr reference operator[](size_type idx) const;
|
2019-02-26 01:54:08 +08:00
|
|
|
constexpr reference front() const;
|
|
|
|
constexpr reference back() const;
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr pointer data() const noexcept;
|
|
|
|
|
|
|
|
// [span.iterators], span iterator support
|
|
|
|
constexpr iterator begin() const noexcept;
|
|
|
|
constexpr iterator end() const noexcept;
|
|
|
|
constexpr reverse_iterator rbegin() const noexcept;
|
|
|
|
constexpr reverse_iterator rend() const noexcept;
|
|
|
|
|
|
|
|
private:
|
2019-11-14 22:07:05 +08:00
|
|
|
pointer data_; // exposition only
|
|
|
|
size_type size_; // exposition only
|
2018-07-24 11:01:02 +08:00
|
|
|
};
|
|
|
|
|
2021-10-09 04:57:44 +08:00
|
|
|
template<class It, class EndOrSize>
|
|
|
|
span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
template<class T, size_t N>
|
|
|
|
span(T (&)[N]) -> span<T, N>;
|
2018-08-04 06:36:53 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
template<class T, size_t N>
|
|
|
|
span(array<T, N>&) -> span<T, N>;
|
|
|
|
|
|
|
|
template<class T, size_t N>
|
|
|
|
span(const array<T, N>&) -> span<const T, N>;
|
|
|
|
|
2021-10-09 04:57:44 +08:00
|
|
|
template<class R>
|
|
|
|
span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-02-15 02:41:09 +08:00
|
|
|
#include <__assert>
|
2018-07-24 11:56:38 +08:00
|
|
|
#include <__config>
|
2021-05-13 11:04:03 +08:00
|
|
|
#include <__debug>
|
2021-10-09 04:57:44 +08:00
|
|
|
#include <__iterator/concepts.h>
|
2021-06-11 21:55:11 +08:00
|
|
|
#include <__iterator/wrap_iter.h>
|
2021-10-09 04:57:44 +08:00
|
|
|
#include <__ranges/concepts.h>
|
|
|
|
#include <__ranges/data.h>
|
2020-11-25 01:08:02 +08:00
|
|
|
#include <__ranges/enable_borrowed_range.h>
|
2021-05-14 14:20:07 +08:00
|
|
|
#include <__ranges/enable_view.h>
|
2021-10-09 04:57:44 +08:00
|
|
|
#include <__ranges/size.h>
|
2018-07-24 11:01:02 +08:00
|
|
|
#include <array> // for array
|
|
|
|
#include <cstddef> // for byte
|
2020-02-11 18:16:40 +08:00
|
|
|
#include <iterator> // for iterators
|
2021-06-10 07:10:17 +08:00
|
|
|
#include <limits>
|
2020-02-11 18:16:40 +08:00
|
|
|
#include <type_traits> // for remove_cv, etc
|
2021-07-14 03:44:07 +08:00
|
|
|
#include <version>
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2018-07-24 11:01:02 +08:00
|
|
|
#endif
|
|
|
|
|
2020-11-28 03:13:05 +08:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 17
|
|
|
|
|
2020-11-28 03:13:05 +08:00
|
|
|
inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
|
2019-02-27 08:32:16 +08:00
|
|
|
template <typename _Tp, size_t _Extent = dynamic_extent> class span;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
template <class _Tp>
|
2021-10-09 04:57:44 +08:00
|
|
|
struct __is_std_array : false_type {};
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2021-10-09 04:57:44 +08:00
|
|
|
template <class _Tp, size_t _Sz>
|
|
|
|
struct __is_std_array<array<_Tp, _Sz>> : true_type {};
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
template <class _Tp>
|
2021-10-09 04:57:44 +08:00
|
|
|
struct __is_std_span : false_type {};
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
template <class _Tp, size_t _Sz>
|
2021-10-09 04:57:44 +08:00
|
|
|
struct __is_std_span<span<_Tp, _Sz>> : true_type {};
|
2018-07-24 11:01:02 +08:00
|
|
|
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2021-10-09 04:57:44 +08:00
|
|
|
template <class _Range, class _ElementType>
|
|
|
|
concept __span_compatible_range =
|
|
|
|
ranges::contiguous_range<_Range> &&
|
|
|
|
ranges::sized_range<_Range> &&
|
|
|
|
(ranges::borrowed_range<_Range> || is_const_v<_ElementType>) &&
|
|
|
|
!__is_std_span<remove_cvref_t<_Range>>::value &&
|
|
|
|
!__is_std_array<remove_cvref_t<_Range>>::value &&
|
|
|
|
!is_array_v<remove_cvref_t<_Range>> &&
|
|
|
|
is_convertible_v<remove_reference_t<ranges::range_reference_t<_Range>>(*)[], _ElementType(*)[]>;
|
|
|
|
#endif
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <typename _Tp, size_t _Extent>
|
2018-07-24 11:01:02 +08:00
|
|
|
class _LIBCPP_TEMPLATE_VIS span {
|
|
|
|
public:
|
|
|
|
// constants and types
|
|
|
|
using element_type = _Tp;
|
|
|
|
using value_type = remove_cv_t<_Tp>;
|
2019-11-14 22:07:05 +08:00
|
|
|
using size_type = size_t;
|
2018-07-24 11:01:02 +08:00
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = _Tp *;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_pointer = const _Tp *;
|
2018-07-24 11:01:02 +08:00
|
|
|
using reference = _Tp &;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_reference = const _Tp &;
|
2021-04-21 10:08:00 +08:00
|
|
|
#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
|
|
|
|
using iterator = pointer;
|
|
|
|
#else
|
|
|
|
using iterator = __wrap_iter<pointer>;
|
|
|
|
#endif
|
2018-07-24 11:01:02 +08:00
|
|
|
using reverse_iterator = _VSTD::reverse_iterator<iterator>;
|
|
|
|
|
2019-11-14 22:07:05 +08:00
|
|
|
static constexpr size_type extent = _Extent;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2018-08-04 06:36:53 +08:00
|
|
|
// [span.cons], span constructors, copy, assignment, and destructor
|
2020-05-14 21:28:27 +08:00
|
|
|
template <size_t _Sz = _Extent, enable_if_t<_Sz == 0, nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} {}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
constexpr span (const span&) noexcept = default;
|
|
|
|
constexpr span& operator=(const span&) noexcept = default;
|
|
|
|
|
2022-02-01 01:04:08 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2021-10-09 04:57:44 +08:00
|
|
|
template <class _It,
|
|
|
|
enable_if_t<contiguous_iterator<_It> &&
|
|
|
|
is_convertible_v<remove_reference_t<iter_reference_t<_It>>(*)[], element_type (*)[]>,
|
|
|
|
nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr explicit span(_It __first, size_type __count)
|
|
|
|
: __data{_VSTD::to_address(__first)} {
|
|
|
|
(void)__count;
|
|
|
|
_LIBCPP_ASSERT(_Extent == __count, "size mismatch in span's constructor (iterator, len)");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <
|
|
|
|
class _It, class _End,
|
|
|
|
enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
|
|
|
|
contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
|
|
|
|
nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr explicit span(_It __first, _End __last) : __data{_VSTD::to_address(__first)} {
|
|
|
|
(void)__last;
|
|
|
|
_LIBCPP_ASSERT((__last - __first >= 0), "invalid range in span's constructor (iterator, sentinel)");
|
|
|
|
_LIBCPP_ASSERT(__last - __first == _Extent,
|
|
|
|
"invalid range in span's constructor (iterator, sentinel): last - first != extent");
|
|
|
|
}
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2021-10-15 05:02:43 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr span(type_identity_t<element_type> (&__arr)[_Extent]) noexcept : __data{__arr} {}
|
2020-05-14 22:50:03 +08:00
|
|
|
|
|
|
|
template <class _OtherElementType,
|
|
|
|
enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span(array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
|
|
|
|
|
|
|
|
template <class _OtherElementType,
|
|
|
|
enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span(const array<_OtherElementType, _Extent>& __arr) noexcept : __data{__arr.data()} {}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2021-10-09 04:57:44 +08:00
|
|
|
template <__span_compatible_range<element_type> _Range>
|
2020-05-13 21:50:06 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2021-10-09 04:57:44 +08:00
|
|
|
constexpr explicit span(_Range&& __r) : __data{ranges::data(__r)} {
|
|
|
|
_LIBCPP_ASSERT(ranges::size(__r) == _Extent, "size mismatch in span's constructor (range)");
|
|
|
|
}
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2020-05-13 21:50:06 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
template <class _OtherElementType>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span(const span<_OtherElementType, _Extent>& __other,
|
|
|
|
enable_if_t<
|
|
|
|
is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
|
|
|
|
nullptr_t> = nullptr)
|
|
|
|
: __data{__other.data()} {}
|
|
|
|
|
|
|
|
template <class _OtherElementType>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2020-05-13 21:50:06 +08:00
|
|
|
constexpr explicit span(const span<_OtherElementType, dynamic_extent>& __other,
|
2018-07-24 11:01:02 +08:00
|
|
|
enable_if_t<
|
|
|
|
is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
|
|
|
|
nullptr_t> = nullptr) noexcept
|
|
|
|
: __data{__other.data()} { _LIBCPP_ASSERT(_Extent == __other.size(), "size mismatch in span's constructor (other span)"); }
|
|
|
|
|
|
|
|
|
|
|
|
// ~span() noexcept = default;
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Count>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span<element_type, _Count> first() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
|
|
|
static_assert(_Count <= _Extent, "Count out of range in span::first()");
|
2020-05-13 21:50:06 +08:00
|
|
|
return span<element_type, _Count>{data(), _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Count>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span<element_type, _Count> last() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
|
|
|
static_assert(_Count <= _Extent, "Count out of range in span::last()");
|
2020-05-13 21:50:06 +08:00
|
|
|
return span<element_type, _Count>{data() + size() - _Count, _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
2018-08-04 06:36:53 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data(), __count};
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr span<element_type, dynamic_extent> last(size_type __count) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data() + size() - __count, __count};
|
|
|
|
}
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Offset, size_t _Count = dynamic_extent>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr auto subspan() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
-> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>
|
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()");
|
2020-02-12 23:20:09 +08:00
|
|
|
static_assert(_Count == dynamic_extent || _Count <= _Extent - _Offset, "Offset + count out of range in span::subspan()");
|
2020-05-13 21:50:06 +08:00
|
|
|
|
|
|
|
using _ReturnType = span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset>;
|
|
|
|
return _ReturnType{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span<element_type, dynamic_extent>
|
2019-11-14 22:07:05 +08:00
|
|
|
subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
|
2018-08-04 06:36:53 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
|
|
|
|
_LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
if (__count == dynamic_extent)
|
|
|
|
return {data() + __offset, size() - __offset};
|
2020-02-12 23:20:09 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data() + __offset, __count};
|
|
|
|
}
|
|
|
|
|
2021-10-13 10:30:58 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return _Extent; }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return _Extent * sizeof(element_type); }
|
|
|
|
[[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return _Extent == 0; }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-11-14 22:07:05 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2020-02-11 18:38:00 +08:00
|
|
|
_LIBCPP_ASSERT(__idx < size(), "span<T,N>[] index out of bounds");
|
2018-08-04 06:36:53 +08:00
|
|
|
return __data[__idx];
|
|
|
|
}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-26 01:54:08 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2020-02-14 21:31:15 +08:00
|
|
|
_LIBCPP_ASSERT(!empty(), "span<T, N>::front() on empty span");
|
2019-02-26 01:54:08 +08:00
|
|
|
return __data[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
|
|
|
|
{
|
2020-02-14 21:31:15 +08:00
|
|
|
_LIBCPP_ASSERT(!empty(), "span<T, N>::back() on empty span");
|
2019-02-26 01:54:08 +08:00
|
|
|
return __data[size()-1];
|
2018-08-04 06:36:53 +08:00
|
|
|
}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
|
|
|
|
|
|
|
|
// [span.iter], span iterator support
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept
|
2020-05-13 21:50:06 +08:00
|
|
|
{ return span<const byte, _Extent * sizeof(element_type)>{reinterpret_cast<const byte *>(data()), size_bytes()}; }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-03-28 09:27:52 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept
|
2020-05-13 21:50:06 +08:00
|
|
|
{ return span<byte, _Extent * sizeof(element_type)>{reinterpret_cast<byte *>(data()), size_bytes()}; }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
pointer __data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename _Tp>
|
|
|
|
class _LIBCPP_TEMPLATE_VIS span<_Tp, dynamic_extent> {
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constants and types
|
|
|
|
using element_type = _Tp;
|
|
|
|
using value_type = remove_cv_t<_Tp>;
|
2019-11-14 22:07:05 +08:00
|
|
|
using size_type = size_t;
|
2018-07-24 11:01:02 +08:00
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = _Tp *;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_pointer = const _Tp *;
|
2018-07-24 11:01:02 +08:00
|
|
|
using reference = _Tp &;
|
2019-02-26 01:58:03 +08:00
|
|
|
using const_reference = const _Tp &;
|
2021-04-21 10:08:00 +08:00
|
|
|
#if (_LIBCPP_DEBUG_LEVEL == 2) || defined(_LIBCPP_ABI_SPAN_POINTER_ITERATORS)
|
|
|
|
using iterator = pointer;
|
|
|
|
#else
|
|
|
|
using iterator = __wrap_iter<pointer>;
|
|
|
|
#endif
|
2018-07-24 11:01:02 +08:00
|
|
|
using reverse_iterator = _VSTD::reverse_iterator<iterator>;
|
|
|
|
|
2019-11-14 22:07:05 +08:00
|
|
|
static constexpr size_type extent = dynamic_extent;
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2018-08-04 06:36:53 +08:00
|
|
|
// [span.cons], span constructors, copy, assignment, and destructor
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr}, __size{0} {}
|
|
|
|
|
|
|
|
constexpr span (const span&) noexcept = default;
|
|
|
|
constexpr span& operator=(const span&) noexcept = default;
|
|
|
|
|
2022-02-01 01:04:08 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2021-10-09 04:57:44 +08:00
|
|
|
template <class _It,
|
|
|
|
enable_if_t<contiguous_iterator<_It> &&
|
|
|
|
is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]>,
|
|
|
|
nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span(_It __first, size_type __count)
|
|
|
|
: __data{_VSTD::to_address(__first)}, __size{__count} {}
|
|
|
|
|
|
|
|
template <
|
|
|
|
class _It, class _End,
|
|
|
|
enable_if_t<is_convertible_v<remove_reference_t<iter_reference_t<_It> > (*)[], element_type (*)[]> &&
|
|
|
|
contiguous_iterator<_It> && sized_sentinel_for<_End, _It> && !is_convertible_v<_End, size_t>,
|
|
|
|
nullptr_t> = nullptr>
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span(_It __first, _End __last)
|
|
|
|
: __data(_VSTD::to_address(__first)), __size(__last - __first) {}
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2018-07-24 11:01:02 +08:00
|
|
|
|
|
|
|
template <size_t _Sz>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2021-10-15 05:02:43 +08:00
|
|
|
constexpr span(type_identity_t<element_type> (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2020-05-14 22:50:03 +08:00
|
|
|
template <class _OtherElementType, size_t _Sz,
|
|
|
|
enable_if_t<is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2020-05-14 22:50:03 +08:00
|
|
|
constexpr span(array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
|
2018-08-04 06:36:53 +08:00
|
|
|
|
2020-05-14 22:50:03 +08:00
|
|
|
template <class _OtherElementType, size_t _Sz,
|
|
|
|
enable_if_t<is_convertible_v<const _OtherElementType(*)[], element_type (*)[]>, nullptr_t> = nullptr>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2020-05-14 22:50:03 +08:00
|
|
|
constexpr span(const array<_OtherElementType, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2021-10-09 04:57:44 +08:00
|
|
|
template <__span_compatible_range<element_type> _Range>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2021-10-09 04:57:44 +08:00
|
|
|
constexpr span(_Range&& __r) : __data(ranges::data(__r)), __size{ranges::size(__r)} {}
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class _OtherElementType, size_t _OtherExtent>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2018-07-24 11:01:02 +08:00
|
|
|
constexpr span(const span<_OtherElementType, _OtherExtent>& __other,
|
|
|
|
enable_if_t<
|
|
|
|
is_convertible_v<_OtherElementType(*)[], element_type (*)[]>,
|
|
|
|
nullptr_t> = nullptr) noexcept
|
|
|
|
: __data{__other.data()}, __size{__other.size()} {}
|
|
|
|
|
|
|
|
// ~span() noexcept = default;
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Count>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span<element_type, _Count> first() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
|
|
|
_LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()");
|
2020-05-13 21:50:06 +08:00
|
|
|
return span<element_type, _Count>{data(), _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Count>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
constexpr span<element_type, _Count> last() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
|
|
|
_LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()");
|
2020-05-13 21:50:06 +08:00
|
|
|
return span<element_type, _Count>{data() + size() - _Count, _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr span<element_type, dynamic_extent> first(size_type __count) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data(), __count};
|
|
|
|
}
|
2018-08-04 06:36:53 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-11-14 22:07:05 +08:00
|
|
|
constexpr span<element_type, dynamic_extent> last (size_type __count) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data() + size() - __count, __count};
|
|
|
|
}
|
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <size_t _Offset, size_t _Count = dynamic_extent>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2020-02-11 18:57:35 +08:00
|
|
|
constexpr span<element_type, _Count> subspan() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()");
|
2020-02-12 23:20:09 +08:00
|
|
|
_LIBCPP_ASSERT(_Count == dynamic_extent || _Count <= size() - _Offset, "Offset + count out of range in span::subspan()");
|
2020-05-13 21:50:06 +08:00
|
|
|
return span<element_type, _Count>{data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count};
|
2018-07-24 11:01:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr span<element_type, dynamic_extent>
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-11-14 22:07:05 +08:00
|
|
|
subspan(size_type __offset, size_type __count = dynamic_extent) const noexcept
|
2018-08-04 06:36:53 +08:00
|
|
|
{
|
2019-03-06 11:59:44 +08:00
|
|
|
_LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)");
|
|
|
|
_LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
if (__count == dynamic_extent)
|
|
|
|
return {data() + __offset, size() - __offset};
|
2020-02-12 23:20:09 +08:00
|
|
|
_LIBCPP_ASSERT(__count <= size() - __offset, "Offset + count out of range in span::subspan(offset, count)");
|
2018-07-24 11:01:02 +08:00
|
|
|
return {data() + __offset, __count};
|
|
|
|
}
|
|
|
|
|
2021-10-13 10:30:58 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr size_type size() const noexcept { return __size; }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr size_type size_bytes() const noexcept { return __size * sizeof(element_type); }
|
|
|
|
[[nodiscard]] _LIBCPP_INLINE_VISIBILITY constexpr bool empty() const noexcept { return __size == 0; }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-11-14 22:07:05 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference operator[](size_type __idx) const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2020-02-11 18:38:00 +08:00
|
|
|
_LIBCPP_ASSERT(__idx < size(), "span<T>[] index out of bounds");
|
2018-08-04 06:36:53 +08:00
|
|
|
return __data[__idx];
|
|
|
|
}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-26 01:54:08 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{
|
2019-02-26 01:54:08 +08:00
|
|
|
_LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span");
|
|
|
|
return __data[0];
|
2018-08-04 06:36:53 +08:00
|
|
|
}
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-26 01:54:08 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept
|
|
|
|
{
|
|
|
|
_LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span");
|
|
|
|
return __data[size()-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; }
|
|
|
|
|
|
|
|
// [span.iter], span iterator support
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr iterator begin() const noexcept { return iterator(data()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr iterator end() const noexcept { return iterator(data() + size()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
|
|
|
|
_LIBCPP_INLINE_VISIBILITY constexpr reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept
|
|
|
|
{ return {reinterpret_cast<const byte *>(data()), size_bytes()}; }
|
|
|
|
|
2019-03-28 09:27:52 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept
|
2018-07-24 11:01:02 +08:00
|
|
|
{ return {reinterpret_cast<byte *>(data()), size_bytes()}; }
|
|
|
|
|
|
|
|
private:
|
2019-11-14 22:07:05 +08:00
|
|
|
pointer __data;
|
|
|
|
size_type __size;
|
2018-07-24 11:01:02 +08:00
|
|
|
};
|
|
|
|
|
2022-02-01 01:04:08 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2020-11-25 01:08:02 +08:00
|
|
|
template <class _Tp, size_t _Extent>
|
|
|
|
inline constexpr bool ranges::enable_borrowed_range<span<_Tp, _Extent> > = true;
|
2021-05-14 14:20:07 +08:00
|
|
|
|
|
|
|
template <class _ElementType, size_t _Extent>
|
|
|
|
inline constexpr bool ranges::enable_view<span<_ElementType, _Extent>> = true;
|
2022-02-01 01:04:08 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2020-11-25 01:08:02 +08:00
|
|
|
|
2019-03-28 09:27:52 +08:00
|
|
|
// as_bytes & as_writable_bytes
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class _Tp, size_t _Extent>
|
2019-02-27 23:41:37 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
auto as_bytes(span<_Tp, _Extent> __s) noexcept
|
|
|
|
-> decltype(__s.__as_bytes())
|
|
|
|
{ return __s.__as_bytes(); }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2019-02-27 08:32:16 +08:00
|
|
|
template <class _Tp, size_t _Extent>
|
2019-02-27 23:41:37 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2019-03-28 09:27:52 +08:00
|
|
|
auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept
|
|
|
|
-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())>
|
|
|
|
{ return __s.__as_writable_bytes(); }
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2022-02-01 01:04:08 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2021-10-09 04:57:44 +08:00
|
|
|
template<contiguous_iterator _It, class _EndOrSize>
|
|
|
|
span(_It, _EndOrSize) -> span<remove_reference_t<iter_reference_t<_It>>>;
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
2021-10-09 04:57:44 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
template<class _Tp, size_t _Sz>
|
|
|
|
span(_Tp (&)[_Sz]) -> span<_Tp, _Sz>;
|
2018-08-04 06:36:53 +08:00
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
template<class _Tp, size_t _Sz>
|
|
|
|
span(array<_Tp, _Sz>&) -> span<_Tp, _Sz>;
|
|
|
|
|
|
|
|
template<class _Tp, size_t _Sz>
|
|
|
|
span(const array<_Tp, _Sz>&) -> span<const _Tp, _Sz>;
|
|
|
|
|
[libc++] Guard much of std::ranges under _LIBCPP_HAS_NO_INCOMPLETE_RANGES.
The logic here is that we are disabling *only* things in `std::ranges::`.
Everything in `std::` is permitted, including `default_sentinel`, `contiguous_iterator`,
`common_iterator`, `projected`, `swappable`, and so on. Then, we include
anything from `std::ranges::` that is required in order to make those things
work: `ranges::swap`, `ranges::swap_ranges`, `input_range`, `ranges::begin`,
`ranges::iter_move`, and so on. But then that's all. Everything else (including
notably all of the "views" and the `std::views` namespace itself) is still
locked up behind `_LIBCPP_HAS_NO_INCOMPLETE_RANGES`.
Differential Revision: https://reviews.llvm.org/D118736
2022-02-02 05:52:02 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
|
2021-10-09 04:57:44 +08:00
|
|
|
template<ranges::contiguous_range _Range>
|
|
|
|
span(_Range&&) -> span<remove_reference_t<ranges::range_reference_t<_Range>>>;
|
|
|
|
#endif
|
2018-07-24 11:01:02 +08:00
|
|
|
|
2018-07-24 11:56:38 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 17
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2020-11-28 03:13:05 +08:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2018-07-24 11:01:02 +08:00
|
|
|
#endif // _LIBCPP_SPAN
|