optris::sdk::Span
A pointer and a count. Copying one copies the view, never the elements, and the caller owns the lifetime of what it points at -- the same contract as std::span.
Template parameters
| Name | Description |
|---|---|
T |
Element type. Use const T for a read-only view, which is what all but one of the SDK's own uses want. |
Public types
element_type
T element_type
The element type, const-qualified or not.
value_type
std::remove_cv_t< T > value_type
The element type without const, as the standard containers spell it.
size_type
std::size_t size_type
Element count type.
difference_type
std::ptrdiff_t difference_type
Iterator distance type.
pointer
T * pointer
Pointer to an element.
const_pointer
const T * const_pointer
Const pointer to an element.
reference
T & reference
Reference to an element.
const_reference
const T & const_reference
Const reference.
iterator
T * iterator
Forward iterator.
const_iterator
const T * const_iterator
Const forward iterator.
reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator, for rbegin()/rend().
Public functions
Span
constexpr Span() noexcept
An empty view. Points at nothing, which is distinct from pointing at an empty container only in that data() is null.
Span
constexpr Span(pointer first, size_type count) noexcept
count elements starting at first.
Span
constexpr Span(pointer first, pointer last) noexcept
[first, last). last is one past the end, as everywhere else.
Span
constexpr Span(element_type(&array)[N]) noexcept
A C array, including a string literal for Span<const char>`.
Span
constexpr Span(Container &&container)
Any contiguous container -- std::vector, std::array, std::string, std::string_view, and std::span itself in the SDK's own C++23 sources -- implicitly, which is what makes this a drop-in for the std::span parameters it replaced.
A forwarding reference rather than Container &, so an rvalue binds. That is not a nicety: the first version took Container &, built clean against include/, and then failed the library build at nine sites in three files -- every one of them handing over a temporary, std::span<const [Rgb24](/documentation/sdks/otc-sdk/v12.0/api/classes/optris.sdk.rgb24)>(custom_palette->colors) in client_bridge.h and the std::span returns of the GPU backend's buffer getters in imager.cc. A non-const lvalue reference cannot bind to any of those. std::span's own range constructor takes R && for the same reason.
The dangling risk that comes with it is exactly std::span's: viewing a temporary container is the caller's mistake in both types, and the sites above are views over storage somebody else owns.
Deducing the reference rather than fixing const on it is what lets one constructor serve all four cases: written as two overloads it would either reject Span<const T> from a mutable vector or accept [Span](/documentation/sdks/otc-sdk/v12.0/api/classes/optris.sdk.span)<T> from a const one. The element-type test above is what decides which is allowed.
Span
constexpr Span(const Span< U > &other) noexcept
Span<T> to [Span](/documentation/sdks/otc-sdk/v12.0/api/classes/optris.sdk.span)<const T>, the one conversion between two Spans that is always safe.
data
constexpr pointer data() const noexcept
Returns: The first element's address, or null for a default-built view. Never dereference it without checking size().
size
constexpr size_type size() const noexcept
Returns: How many elements the view covers.
size_bytes
constexpr size_type size_bytes() const noexcept
Returns: size() * sizeof(element_type), for a byte-wise copy.
empty
constexpr bool empty() const noexcept
Returns: True when the view covers no elements.
operator[]
constexpr reference operator[](size_type index) const
Unchecked element access, as on std::span and std::vector.
Parameters
| Name | Description |
|---|---|
index |
Must be below size(). |
Returns: A reference to that element.
front
constexpr reference front() const
Returns: The first element. Undefined on an empty view.
back
constexpr reference back() const
Returns: The last element. Undefined on an empty view.
begin
constexpr iterator begin() const noexcept
Returns: An iterator to the first element.
end
constexpr iterator end() const noexcept
Returns: An iterator one past the last element.
cbegin
constexpr const_iterator cbegin() const noexcept
Returns: A const iterator to the first element.
cend
constexpr const_iterator cend() const noexcept
Returns: A const iterator one past the last element.
rbegin
constexpr reverse_iterator rbegin() const noexcept
Returns: A reverse iterator to the last element.
rend
constexpr reverse_iterator rend() const noexcept
Returns: A reverse iterator one before the first element.
first
constexpr Span first(size_type count) const
Parameters
| Name | Description |
|---|---|
count |
Must be no greater than size(). |
Returns: A view of the first count elements.
last
constexpr Span last(size_type count) const
Parameters
| Name | Description |
|---|---|
count |
Must be no greater than size(). |
Returns: A view of the last count elements.
subspan
constexpr Span subspan(size_type offset, size_type count=static_cast< size_type >(-1)) const
count defaults to "the rest", spelled as the largest size_type for the same reason std::span spells it dynamic_extent: there is no other value that cannot also be a real length.