OTB  9.0.0
Orfeo Toolbox
List of all members
otb::Span< T > Struct Template Reference

#include <otbSpan.h>

Public Types

Typedefs
using element_type = T
 
using value_type = std::remove_cv_t< T >
 
using index_type = std::vcl_size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = T *
 
using const_pointer = T const *
 
using reference = T &
 
using const_reference = T const &
 
using iterator = T *
 
using const_iterator = T const *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

Constructors
constexpr Span () noexcept=default
 
constexpr Span (pointer ptr, index_type count) noexcept
 
constexpr Span (pointer first, pointer last) noexcept
 
template<std::vcl_size_t N>
constexpr Span (element_type(&arr)[N]) noexcept
 
template<class Container >
constexpr Span (Container &&cont) noexcept
 
template<class U >
constexpr Span (const otb::Span< U > &s) noexcept
 
constexpr Span (const Span &other) noexcept=default
 
Spanoperator= (Span const &) noexcept=default
 
 ~Span ()=default
 
Iterators
OTB_MB_CSTXPR iterator begin () noexcept
 
OTB_MB_CSTXPR iterator end () noexcept
 
constexpr const_iterator begin () const noexcept
 
constexpr const_iterator end () const noexcept
 
constexpr const_iterator cbegin () const noexcept
 
constexpr const_iterator cend () const noexcept
 
OTB_MB_CSTXPR reverse_iterator rbegin () noexcept
 
OTB_MB_CSTXPR reverse_iterator rend () noexcept
 
constexpr const_reverse_iterator crbegin () const noexcept
 
constexpr const_reverse_iterator crend () const noexcept
 
Element access
OTB_MB_CSTXPR pointer data () noexcept
 
constexpr const_pointer data () const noexcept
 
OTB_MB_CSTXPR reference front () noexcept
 
constexpr const_reference front () const noexcept
 
OTB_MB_CSTXPR reference back () noexcept
 
constexpr const_reference back () const noexcept
 
OTB_MB_CSTXPR reference operator[] (index_type p) noexcept
 
constexpr const_reference operator[] (index_type p) const noexcept
 
Observers
constexpr index_type size () const noexcept
 
constexpr bool empty () const noexcept
 

Subviews

pointer m_buffer = nullptr
 
index_type m_size = 0
 
constexpr Span first (index_type n) const noexcept
 
constexpr Span last (index_type n) const noexcept
 
constexpr Span subspan (index_type offset, index_type count=std::numeric_limits< index_type >::max()) const noexcept
 

Detailed Description

template<typename T>
struct otb::Span< T >

Span class inspired by C++20 standard.

Invariant
size() == 0 or data() != nullptr
Note
Unlike C++20 std::span this implementation doesn't follow Lakos Rule but instead non-throwing functions are noexcept as suggested in https://wg21.link/p1656. Beware to not expect operator[] to always be noexcept as it won't be anymore once this class is deprecated in favour of std::span in a few years.
This implementation only support spans with dynamic extents. Static extents are not supported (yet?)
Todo:
fix RW / RO interface
Author
Luc Hermitte (CS Group)

Definition at line 60 of file otbSpan.h.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using otb::Span< T >::const_iterator = T const*

Definition at line 74 of file otbSpan.h.

◆ const_pointer

template<typename T >
using otb::Span< T >::const_pointer = T const*

Definition at line 70 of file otbSpan.h.

◆ const_reference

template<typename T >
using otb::Span< T >::const_reference = T const&

Definition at line 72 of file otbSpan.h.

◆ const_reverse_iterator

template<typename T >
using otb::Span< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 76 of file otbSpan.h.

◆ difference_type

template<typename T >
using otb::Span< T >::difference_type = std::ptrdiff_t

Definition at line 68 of file otbSpan.h.

◆ element_type

template<typename T >
using otb::Span< T >::element_type = T

Definition at line 65 of file otbSpan.h.

◆ index_type

template<typename T >
using otb::Span< T >::index_type = std::vcl_size_t

Definition at line 67 of file otbSpan.h.

◆ iterator

template<typename T >
using otb::Span< T >::iterator = T*

Definition at line 73 of file otbSpan.h.

◆ pointer

template<typename T >
using otb::Span< T >::pointer = T*

Definition at line 69 of file otbSpan.h.

◆ reference

template<typename T >
using otb::Span< T >::reference = T&

Definition at line 71 of file otbSpan.h.

◆ reverse_iterator

template<typename T >
using otb::Span< T >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 75 of file otbSpan.h.

◆ value_type

template<typename T >
using otb::Span< T >::value_type = std::remove_cv_t<T>

Definition at line 66 of file otbSpan.h.

Constructor & Destructor Documentation

◆ Span() [1/7]

template<typename T >
constexpr otb::Span< T >::Span ( )
constexprdefaultnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Referenced by otb::Span< T >::first(), otb::Span< T >::last(), and otb::Span< T >::subspan().

◆ Span() [2/7]

template<typename T >
constexpr otb::Span< T >::Span ( pointer  ptr,
index_type  count 
)
inlineconstexprnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Definition at line 82 of file otbSpan.h.

◆ Span() [3/7]

template<typename T >
constexpr otb::Span< T >::Span ( pointer  first,
pointer  last 
)
inlineconstexprnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Definition at line 87 of file otbSpan.h.

References otb::Span< T >::first(), and otb::Span< T >::last().

◆ Span() [4/7]

template<typename T >
template<std::vcl_size_t N>
constexpr otb::Span< T >::Span ( element_type(&)  arr[N])
inlineconstexprnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Definition at line 93 of file otbSpan.h.

◆ Span() [5/7]

template<typename T >
template<class Container >
constexpr otb::Span< T >::Span ( Container &&  cont)
inlineconstexprnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Definition at line 114 of file otbSpan.h.

◆ Span() [6/7]

template<typename T >
template<class U >
constexpr otb::Span< T >::Span ( const otb::Span< U > &  s)
inlineconstexprnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

Definition at line 121 of file otbSpan.h.

◆ Span() [7/7]

template<typename T >
constexpr otb::Span< T >::Span ( const Span< T > &  other)
constexprdefaultnoexcept

Converting constructor from a contiguous container.

Precondition
The Container shall be contiguous
Warning
The lifetime of the span shall not exceed the one of the container. Be sure to not store the span locally, and initialize it from a rvalue. The use case where a span is initialized from a rvalue shall be restricted to function parameters.
std::vector<T> f();
void g(Span<T> sp);
...
Span<T> sp(f()); // NO!!! Use after release
g(f()); // OK!!
Todo:
static_assert the container is contiguous

◆ ~Span()

template<typename T >
otb::Span< T >::~Span ( )
default

No-op destructor.

Member Function Documentation

◆ back() [1/2]

template<typename T >
constexpr const_reference otb::Span< T >::back ( ) const
inlineconstexprnoexcept

◆ back() [2/2]

template<typename T >
OTB_MB_CSTXPR reference otb::Span< T >::back ( )
inlinenoexcept

◆ begin() [1/2]

template<typename T >
constexpr const_iterator otb::Span< T >::begin ( ) const
inlineconstexprnoexcept

Definition at line 138 of file otbSpan.h.

References otb::Span< T >::data().

◆ begin() [2/2]

template<typename T >
OTB_MB_CSTXPR iterator otb::Span< T >::begin ( )
inlinenoexcept

Definition at line 136 of file otbSpan.h.

References otb::Span< T >::data().

Referenced by otb::Span< T >::rend().

◆ cbegin()

template<typename T >
constexpr const_iterator otb::Span< T >::cbegin ( ) const
inlineconstexprnoexcept

Definition at line 140 of file otbSpan.h.

References otb::Span< T >::data().

Referenced by otb::Span< T >::crend().

◆ cend()

template<typename T >
constexpr const_iterator otb::Span< T >::cend ( ) const
inlineconstexprnoexcept

Definition at line 141 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::size().

Referenced by otb::Span< T >::crbegin().

◆ crbegin()

template<typename T >
constexpr const_reverse_iterator otb::Span< T >::crbegin ( ) const
inlineconstexprnoexcept

Definition at line 146 of file otbSpan.h.

References otb::Span< T >::cend().

◆ crend()

template<typename T >
constexpr const_reverse_iterator otb::Span< T >::crend ( ) const
inlineconstexprnoexcept

Definition at line 147 of file otbSpan.h.

References otb::Span< T >::cbegin().

◆ data() [1/2]

template<typename T >
constexpr const_pointer otb::Span< T >::data ( ) const
inlineconstexprnoexcept

Definition at line 153 of file otbSpan.h.

References otb::Span< T >::m_buffer.

◆ data() [2/2]

template<typename T >
OTB_MB_CSTXPR pointer otb::Span< T >::data ( )
inlinenoexcept

◆ empty()

template<typename T >
constexpr bool otb::Span< T >::empty ( ) const
inlineconstexprnoexcept

◆ end() [1/2]

template<typename T >
constexpr const_iterator otb::Span< T >::end ( ) const
inlineconstexprnoexcept

Definition at line 139 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::size().

◆ end() [2/2]

template<typename T >
OTB_MB_CSTXPR iterator otb::Span< T >::end ( )
inlinenoexcept

Definition at line 137 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::size().

Referenced by otb::Span< T >::rbegin().

◆ first()

template<typename T >
constexpr Span otb::Span< T >::first ( index_type  n) const
inlineconstexprnoexcept

Definition at line 181 of file otbSpan.h.

References otb::Span< T >::data(), otb::Span< T >::size(), and otb::Span< T >::Span().

Referenced by otb::Span< T >::Span().

◆ front() [1/2]

template<typename T >
constexpr const_reference otb::Span< T >::front ( ) const
inlineconstexprnoexcept

Definition at line 155 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::empty().

◆ front() [2/2]

template<typename T >
OTB_MB_CSTXPR reference otb::Span< T >::front ( )
inlinenoexcept

Definition at line 154 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::empty().

◆ last()

template<typename T >
constexpr Span otb::Span< T >::last ( index_type  n) const
inlineconstexprnoexcept

Definition at line 183 of file otbSpan.h.

References otb::Span< T >::data(), otb::Span< T >::size(), and otb::Span< T >::Span().

Referenced by otb::Span< T >::Span().

◆ operator=()

template<typename T >
Span& otb::Span< T >::operator= ( Span< T > const &  )
defaultnoexcept

shallow assignment

◆ operator[]() [1/2]

template<typename T >
constexpr const_reference otb::Span< T >::operator[] ( index_type  p) const
inlineconstexprnoexcept

Definition at line 165 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::size().

◆ operator[]() [2/2]

template<typename T >
OTB_MB_CSTXPR reference otb::Span< T >::operator[] ( index_type  p)
inlinenoexcept

Definition at line 160 of file otbSpan.h.

References otb::Span< T >::data(), and otb::Span< T >::size().

◆ rbegin()

template<typename T >
OTB_MB_CSTXPR reverse_iterator otb::Span< T >::rbegin ( )
inlinenoexcept

Definition at line 144 of file otbSpan.h.

References otb::Span< T >::end().

◆ rend()

template<typename T >
OTB_MB_CSTXPR reverse_iterator otb::Span< T >::rend ( )
inlinenoexcept

Definition at line 145 of file otbSpan.h.

References otb::Span< T >::begin().

◆ size()

template<typename T >
constexpr index_type otb::Span< T >::size ( ) const
inlineconstexprnoexcept

◆ subspan()

template<typename T >
constexpr Span otb::Span< T >::subspan ( index_type  offset,
index_type  count = std::numeric_limits<index_type>::max() 
) const
inlineconstexprnoexcept

Definition at line 187 of file otbSpan.h.

References otb::Span< T >::data(), otb::Span< T >::size(), and otb::Span< T >::Span().

Member Data Documentation

◆ m_buffer

template<typename T >
pointer otb::Span< T >::m_buffer = nullptr
private

Definition at line 202 of file otbSpan.h.

Referenced by otb::Span< T >::data().

◆ m_size

template<typename T >
index_type otb::Span< T >::m_size = 0
private

Definition at line 203 of file otbSpan.h.

Referenced by otb::Span< T >::size().


The documentation for this struct was generated from the following file: