8 #ifndef DIAG_CLIENT_LIB_LIB_PLATFORM_CORE_SPAN_H_ 
    9 #define DIAG_CLIENT_LIB_LIB_PLATFORM_CORE_SPAN_H_ 
   14 #include <type_traits> 
   23 constexpr std::size_t 
dynamic_extent = std::numeric_limits<std::size_t>::max();
 
   34 template<
typename T, std::
size_t Extent = dynamic_extent>
 
   49     std::cerr << message << 
" [" << file_name << 
":" << line_no << 
"]" << std::endl;
 
   60 using remove_cv_ref_t = 
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
 
   75 template<
typename T, std::
size_t Extent>
 
   91 template<
typename T, std::
size_t N>
 
   97 template<
typename T, 
typename = 
void>
 
  107     T, std::void_t<decltype(std::data(std::declval<T>())), decltype(std::size(std::declval<T>()))>>
 
  117 template<
typename T, 
typename ElementType = remove_cv_ref_t<T>>
 
  130 template<
typename, 
typename, 
typename = 
void>
 
  140 template<
typename F, 
typename T>
 
  143     typename std::enable_if<std::is_convertible<
 
  144         std::remove_pointer_t<decltype(std::data(std::declval<F>()))> (*)[], T (*)[]>::value>::type>
 
  154 template<
typename T, std::
size_t Extent>
 
  190 template<
typename T, std::
size_t Extent>
 
  192   static_assert(!std::is_abstract<T>::value,
 
  193                 "A span's element type cannot be an abstract class type");
 
  204   using value_type = 
typename std::remove_cv<element_type>::type;
 
  267   template<std::size_t E = Extent,
 
  268            typename std::enable_if<(E == 
dynamic_extent || E == 0), 
bool>::type = 
true>
 
  295       : 
storage_{first_elem, last_elem - first_elem} {
 
  297                                     "Invalid range", __FILE__, __LINE__);
 
  309   template<std::size_t N, std::size_t E = Extent,
 
  310            typename std::enable_if<
 
  327   template<
typename U, std::size_t N, std::size_t E = Extent,
 
  328            typename std::enable_if<
 
  330                    details::is_container_element_type_convertible<std::array<U, N> &, T>::value,
 
  332   constexpr 
explicit Span(std::array<U, N> &arr) noexcept : 
storage_{arr.data(), N} {}
 
  345   template<
typename U, std::size_t N, std::size_t E = Extent,
 
  347                                        details::is_container_element_type_convertible<
 
  348                                            const std::array<U, N> &, T>::value,
 
  350   constexpr 
explicit Span(
const std::array<U, N> &arr) noexcept : 
storage_{arr.data(), N} {}
 
  364   template<
typename Container, std::size_t E = Extent,
 
  365            typename std::enable_if<
 
  367                    details::is_container_element_type_convertible<Container &, T>::value,
 
  369   constexpr 
explicit Span(Container &cont) noexcept : 
storage_{std::data(cont), std::size(cont)} {}
 
  383   template<
typename Container, std::size_t E = Extent,
 
  384            typename std::enable_if<
 
  386                    details::is_container_element_type_convertible<Container &, T>::value,
 
  388   constexpr 
explicit Span(
const Container &cont) noexcept
 
  389       : 
storage_{std::data(cont), std::size(cont)} {}
 
  409       typename U, std::size_t N,
 
  410       typename std::enable_if<
 
  414       : 
storage_{other_span.data(), other_span.size()} {}
 
  424   constexpr 
Span &operator=(const 
Span &other) noexcept = default;
 
  434   template<std::
size_t Count>
 
  460   template<std::
size_t Count>
 
  490   template<std::
size_t Offset, std::
size_t Count = dynamic_extent>
 
  497         "(Offset <= size() && (Count == dynamic_extent || Count <= size() - " 
  516         "(offset <= size() && (count == dynamic_extent || count <= size() - " 
  538   constexpr 
bool empty() const noexcept { 
return size() == 0u; }
 
  548     return *(
data() + idx);
 
  636 template<
class T, 
size_t N>
 
  639 template<
class T, 
size_t N>
 
  642 template<
class T, 
size_t N>
 
  645 template<
class Container>
 
  647     typename std::remove_reference<decltype(*std::data(std::declval<Container &>()))>::type>;
 
  649 template<
class Container>
 
A view over a contiguous sequence of objects.
 
constexpr reference back() const
Return a reference to the last element of this Span.
 
typename std::remove_cv< element_type >::type value_type
Type alias for the type of values in this Span.
 
const element_type * const_pointer
Type alias type for a pointer to an const element.
 
constexpr Span< element_type, dynamic_extent > last(size_type count) const
Return a subspan containing only the last elements of this Span.
 
constexpr size_type size_bytes() const noexcept
Return the size of this Span in bytes.
 
pointer iterator
The type of an iterator to elements.
 
details::span_storage< T, Extent > storage_
The storage of span related data.
 
element_type & reference
Type alias type for a reference to an element.
 
constexpr pointer data() const noexcept
Return a pointer to the start of the memory block covered by this Span.
 
static constexpr size_type extent
A constant reflecting the configured Extent of this Span.
 
const element_type & const_reference
Type alias type for a reference to an const element.
 
constexpr Span(element_type(&arr)[N]) noexcept
Construct a new Span from the given raw array.
 
constexpr Span(const std::array< U, N > &arr) noexcept
Construct a new Span from the given const std::array.
 
T element_type
Type alias for the type of elements in this Span.
 
constexpr Span(pointer ptr, size_type count)
Construct a new Span from the given pointer and size.
 
constexpr auto subspan() const noexcept -> Span< element_type, Count !=dynamic_extent ? Count :(Extent !=dynamic_extent ? Extent - Offset :dynamic_extent)>
Return a subspan of this Span.
 
std::size_t size_type
Type alias for the type of parameters that indicate a size or a number of values.
 
constexpr const_reverse_iterator crbegin() const noexcept
Return a const_reverse_iterator pointing to the last element of this Span.
 
constexpr Span() noexcept
Default constructor.
 
std::ptrdiff_t difference_type
Type alias for the type of parameters that indicate a difference of indexes into the Span.
 
constexpr size_type size() const noexcept
Return the size of this Span.
 
constexpr Span< element_type, Count > first() const
Return a subspan containing only the first elements of this Span.
 
constexpr Span(const Container &cont) noexcept
Construct a new Span from the given const container.
 
constexpr Span< element_type, dynamic_extent > first(size_type count) const
Return a subspan containing only the first elements of this Span.
 
constexpr Span< element_type, Count > last() const
Return a subspan containing only the last elements of this Span.
 
constexpr Span(const Span &) noexcept=default
Copy construct a new Span from another instance.
 
constexpr Span(Container &cont) noexcept
Construct a new Span from the given container.
 
element_type * pointer
Type alias type for a pointer to an element.
 
constexpr reverse_iterator rbegin() const noexcept
Return a reverse_iterator pointing to the last element of this Span.
 
constexpr Span(std::array< U, N > &arr) noexcept
Construct a new Span from the given std::array.
 
const_pointer const_iterator
The type of a const_iterator to elements.
 
constexpr reverse_iterator rend() const noexcept
Return a reverse_iterator pointing past the first element of this Span.
 
constexpr Span(const Span< U, N > &other_span) noexcept
Converting constructor.
 
~Span() noexcept=default
Destructor.
 
constexpr iterator end() const noexcept
Return an iterator pointing past the last element of this Span.
 
constexpr const_iterator cend() const noexcept
Return a const_iterator pointing past the last element of this Span.
 
constexpr const_reverse_iterator crend() const noexcept
Return a const_reverse_iterator pointing past the first element of this Span.
 
constexpr Span< element_type, dynamic_extent > subspan(size_type offset, size_type count=dynamic_extent) const
Return a subspan of this Span.
 
constexpr bool empty() const noexcept
Return whether this Span is empty.
 
constexpr const_iterator cbegin() const noexcept
Return a const_iterator pointing to the first element of this Span.
 
constexpr reference operator[](size_type idx) const
Return a reference to the n-th element of this Span.
 
constexpr Span(pointer first_elem, pointer last_elem)
Construct a new Span from the open range between [first_elem, last_elem)
 
std::reverse_iterator< iterator > reverse_iterator
The type of a reverse_iterator to elements.
 
constexpr reference front() const
Return a reference to the first element of this Span.
 
std::reverse_iterator< const_iterator > const_reverse_iterator
The type of a const_reverse_iterator to elements.
 
constexpr iterator begin() const noexcept
Return an iterator pointing to the first element of this Span.
 
void CheckIfExpectedOrAbort(bool cond, const char *message, const std::string_view file_name, int line_no)
Check if the condition is as expected otherwise abort with provided message.
 
typename std::remove_cv< typename std::remove_reference< T >::type >::type remove_cv_ref_t
Helper template alias to remove reference and cv and return the actual type.
 
constexpr std::size_t dynamic_extent
A constant for creating Spans with dynamic sizes.
 
Span(T(&)[N]) -> Span< T, N >
 
Checks if std::remove_pointer_t<decltype(std::data(arr))>(*)[] is convertible to T(*)[].
 
Check if the element type is not a specialization of Span, Container is not a specialization of Array...
 
static constexpr bool value
 
Primary template handles std::size, std::data that have no nested ::type member.
 
Primary template handles Span types that have no nested ::type member.
 
Primary template handles std::array types that have no nested ::type member.
 
constexpr span_storage() noexcept=default
 
Storage class needed for span.
 
constexpr span_storage() noexcept=default