5 #include <libcopp/utils/config/libcopp_build_features.h>
8 #if defined(LIBCOPP_MACRO_ENABLE_STD_SPAN) && LIBCOPP_MACRO_ENABLE_STD_SPAN
18 LIBCOPP_COPP_NAMESPACE_BEGIN
24 LIBCOPP_COPP_NAMESPACE_END
32 # include <initializer_list>
34 # include <type_traits>
39 LIBCOPP_COPP_NAMESPACE_BEGIN
43 template <
class TCONTAINER>
44 constexpr
inline auto size(TCONTAINER &&container) -> decltype(container.size()) {
45 return container.size();
48 template <
class T,
size_t SIZE>
49 constexpr
inline size_t size(
const T (&)[SIZE]) noexcept {
53 template <
class TCONTAINER>
54 constexpr
inline auto data(TCONTAINER &&container) -> decltype(container.data()) {
55 return container.data();
58 template <
class T,
size_t SIZE>
59 constexpr
inline T *
data(T (&array_value)[SIZE]) noexcept {
63 template <
class TELEMENT>
64 constexpr
inline const TELEMENT *
data(std::initializer_list<TELEMENT> l) noexcept {
68 template <
class T,
size_t EXTENT = dynamic_extent>
78 template <
class T,
size_t N>
81 template <
class T,
size_t N>
84 template <
class T,
size_t EXTENT>
98 template <
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) {
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>
148 if (c.size() != EXTENT) {
153 template <
class U,
size_t N,
154 typename std::enable_if<N == EXTENT && std::is_convertible<U (*)[], T (*)[]>::value>::type * =
nullptr>
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);
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>
218 template <
class U,
size_t N,
typename std::enable_if<std::is_convertible<U (*)[], T (*)[]>::value>::type * =
nullptr>
230 assert(index < extent_);
246 LIBCOPP_COPP_NAMESPACE_END
249 LIBCOPP_COPP_NAMESPACE_BEGIN
254 template <
class TELEMENT>
259 template <
class TELEMENT>
264 template <
class TELEMENT, std::
size_t N>
269 template <
class TCONTAINER>
275 template <
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>
285 LIBCOPP_COPP_NAMESPACE_END
span(const span &) noexcept=default
span(T *first, T *last) noexcept
bool empty() const noexcept
T * data() const noexcept
span(const std::array< T, N > &array) 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
T & operator[](size_t index) const noexcept
std::ptrdiff_t difference_type
span(C &&c) noexcept(noexcept(c.data(), c.size()))
span(T(&array)[N]) noexcept
T * begin() const 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
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
static constexpr size_t extent
T * data() const noexcept
T & operator[](size_t index) const noexcept
T * begin() 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 size(const T(&)[SIZE]) noexcept
constexpr size_t dynamic_extent
constexpr const TELEMENT * data(std::initializer_list< TELEMENT > l) noexcept
constexpr auto size(TCONTAINER &&container) -> decltype(container.size())
constexpr auto data(TCONTAINER &&container) -> decltype(container.data())
constexpr span< TELEMENT > make_span(TELEMENT *ptr, typename span< TELEMENT >::size_type count)
std::shared_ptr< cli::cmd_option_value > value_type
typename std::decay< TCONTAINER >::type container_type
typename container_type::value_type type