5#include <libcopp/utils/config/libcopp_build_features.h>
8#if defined(LIBCOPP_MACRO_ENABLE_STD_SPAN) && LIBCOPP_MACRO_ENABLE_STD_SPAN
18LIBCOPP_COPP_NAMESPACE_BEGIN
24LIBCOPP_COPP_NAMESPACE_END
32# include <initializer_list>
34# include <type_traits>
39LIBCOPP_COPP_NAMESPACE_BEGIN
43template <
class TCONTAINER>
44constexpr inline auto size(TCONTAINER &&container) ->
decltype(container.size()) {
45 return container.size();
44constexpr inline auto size(TCONTAINER &&container) ->
decltype(container.size()) {
…}
48template <
class T,
size_t SIZE>
49constexpr inline size_t size(
const T (&)[SIZE])
noexcept {
49constexpr inline size_t size(
const T (&)[SIZE])
noexcept {
…}
53template <
class TCONTAINER>
54constexpr inline auto data(TCONTAINER &&container) ->
decltype(container.data()) {
55 return container.data();
54constexpr inline auto data(TCONTAINER &&container) ->
decltype(container.data()) {
…}
58template <
class T,
size_t SIZE>
59constexpr inline T *
data(T (&array_value)[SIZE])
noexcept {
59constexpr inline T *
data(T (&array_value)[SIZE])
noexcept {
…}
63template <
class TELEMENT>
64constexpr inline const TELEMENT *
data(std::initializer_list<TELEMENT> l)
noexcept {
64constexpr inline const TELEMENT *
data(std::initializer_list<TELEMENT> l)
noexcept {
…}
68template <
class T,
size_t EXTENT = dynamic_extent>
78template <
class T,
size_t N>
81template <
class T,
size_t N>
84template <
class T,
size_t EXTENT>
98template <
class T,
size_t EXTENT>
117 template <bool B = EXTENT == 0, typename std::enable_if<B>::type * =
nullptr>
120 span(T *input_data,
size_t count) noexcept :
data_{input_data} {
121 if (count != EXTENT) {
120 span(T *input_data,
size_t count) noexcept :
data_{input_data} {
…}
127 if (std::distance(first, last) != EXTENT) {
132 template <size_t N, typename std::enable_if<EXTENT == N>::type * =
nullptr>
135 template <size_t N, typename std::enable_if<EXTENT == N>::type * =
nullptr>
136 span(std::array<T, N> &array) noexcept :
data_{array.data()} {}
138 template <size_t N, typename std::enable_if<EXTENT == N>::type * =
nullptr>
139 span(
const std::array<T, N> &array) noexcept :
data_{array.data()} {}
142 typename std::enable_if<
143 !detail::is_specialized_span_convertible<typename std::decay<C>::type>::value &&
144 std::is_convertible<typename std::remove_pointer<decltype(std::declval<C>().size())>::type (*)[],
146 std::is_convertible<decltype(std::declval<C>().size()),
size_t>::value>::type * =
nullptr>
147 span(C &&c)
noexcept(
noexcept(c.data(), c.size())) :
data_{c.data()} {
148 if (c.size() != EXTENT) {
147 span(C &&c)
noexcept(
noexcept(c.data(), c.size())) :
data_{c.data()} {
…}
153 template <
class U,
size_t N,
154 typename std::enable_if<N == EXTENT && std::is_convertible<U (*)[], T (*)[]>::value>::type * =
nullptr>
159 bool empty() const noexcept {
return EXTENT == 0; }
163 size_t size() const noexcept {
return EXTENT; }
166 assert(index < EXTENT);
195 span(T *input_data,
size_t count) noexcept : extent_{count},
data_{input_data} {}
197 span(T *first, T *last) noexcept : extent_{
static_cast<size_t>(std::distance(first, last))},
data_{first} {
198 assert(first <= last);
197 span(T *first, T *last) noexcept : extent_{
static_cast<size_t>(std::distance(first, last))},
data_{first} {
…}
202 span(T (&array)[N]) noexcept : extent_{N},
data_{array} {}
205 span(std::array<T, N> &array) noexcept : extent_{N},
data_{array.data()} {}
208 span(
const std::array<T, N> &array) noexcept : extent_{N},
data_{array.data()} {}
211 typename std::enable_if<
212 !detail::is_specialized_span_convertible<typename std::decay<C>::type>::value &&
213 std::is_convertible<typename std::remove_pointer<decltype(std::declval<C>().data())>::type (*)[],
215 std::is_convertible<decltype(std::declval<C>().size()),
size_t>::value>::type * =
nullptr>
216 span(C &&c)
noexcept(
noexcept(c.data(), c.size())) : extent_{c.size()},
data_{c.data()} {}
218 template <
class U,
size_t N,
typename std::enable_if<std::is_convertible<U (*)[], T (*)[]>::value>::type * =
nullptr>
223 bool empty() const noexcept {
return extent_ == 0; }
227 size_t size() const noexcept {
return extent_; }
230 assert(index < extent_);
236 T *
end() const noexcept {
return data_ + extent_; }
246LIBCOPP_COPP_NAMESPACE_END
249LIBCOPP_COPP_NAMESPACE_BEGIN
254template <
class TELEMENT>
259template <
class TELEMENT>
264template <
class TELEMENT, std::
size_t N>
269template <
class TCONTAINER>
272 using type =
typename container_type::value_type;
275template <
class TCONTAINER,
276 typename std::enable_if<
277 !std::is_array<typename std::remove_reference<TCONTAINER>::type>::value &&
278 std::is_pointer<decltype(data(std::declval<TCONTAINER>()))>::value &&
279 std::is_convertible<decltype(size(std::declval<TCONTAINER>())),
size_t>::value>::type* =
nullptr>
285LIBCOPP_COPP_NAMESPACE_END
span(const span &) noexcept=default
T * data() const noexcept
span(T *first, T *last) noexcept
bool empty() const noexcept
span(const std::array< T, N > &array) noexcept
T * begin() const noexcept
span(std::array< T, N > &array) noexcept
const T & const_reference
span(const span< U, N > &other) noexcept
typename std::remove_cv< T >::type value_type
span(T *input_data, size_t count) noexcept
size_t size() const noexcept
std::ptrdiff_t difference_type
span(C &&c) noexcept(noexcept(c.data(), c.size()))
T & operator[](size_t index) const noexcept
span(T(&array)[N]) noexcept
std::reverse_iterator< iterator > reverse_iterator
size_t size() const noexcept
span(T *first, T *last) noexcept
span(C &&c) noexcept(noexcept(c.data(), c.size()))
span(T(&array)[N]) noexcept
const T & const_reference
std::reverse_iterator< iterator > reverse_iterator
T * data() const noexcept
span(const span &) noexcept=default
span(std::array< T, N > &array) noexcept
typename std::remove_cv< T >::type value_type
span(const span< U, N > &other) noexcept
bool empty() const noexcept
T * begin() const noexcept
static constexpr size_t extent
T & operator[](size_t index) const noexcept
span(const std::array< T, N > &array) noexcept
span(T *input_data, size_t count) noexcept
std::ptrdiff_t difference_type
constexpr size_t dynamic_extent
constexpr span< TELEMENT > make_span(TELEMENT *ptr, typename span< TELEMENT >::size_type count)
constexpr auto size(TCONTAINER &&container) -> decltype(container.size())
constexpr auto data(TCONTAINER &&container) -> decltype(container.data())
typename std::decay< TCONTAINER >::type container_type
typename container_type::value_type type