KaMPIng 0.1.1
Flexible and (near) zero-overhead C++ bindings for MPI
Loading...
Searching...
No Matches
kamping::Span< T > Class Template Reference

A span modeled after C++20's std::span. More...

#include <span.hpp>

Public Types

using element_type = T
 Element type; i.e. T.
 
using value_type = std::remove_cv_t<T>
 Value type; i.e. T with volatile and const qualifiers removed.
 
using size_type = size_t
 The type used for the size of the span.
 
using difference_type = std::ptrdiff_t
 The type used for the difference between two elements in the span.
 
using pointer = T*
 The type of a pointer to a single elements in the span.
 
using const_pointer = T const*
 The type of a const pointer to a single elements in the span.
 
using reference = T&
 The type of a reference to a single elements in the span.
 
using const_reference = T const&
 The type of a const reference to a single elements in the span.
 
using iterator = pointer
 The type of an iterator to a single elements in the span.
 
using reverse_iterator
 The type of a reverse iterator to a single elements in the span.
 

Public Member Functions

constexpr Span () noexcept
 Default constructor for an empty span. The pointer is set to nullptr and the size to 0.
 
template<typename It >
constexpr Span (It first, size_type size)
 Constructor for a span from an iterator of type It and a size.
 
template<typename It >
constexpr Span (It first, It last)
 Constructs a span that is a view over the range [first, last); the resulting span has data() == kamping::internal::to_address(first) and size() == last-first.
 
template<typename Range >
constexpr Span (Range &&range)
 Constructs a span that is a view over the range range. The resulting span has data() == std::data(range) and size() == std::size().
 
constexpr pointer data () const noexcept
 Get access to the underlying memory.
 
constexpr iterator begin () const noexcept
 Get iterator pointing to the first element of the span.
 
constexpr iterator end () const noexcept
 Get iterator pointing past the last element of the span.
 
constexpr reverse_iterator rbegin () const noexcept
 Get a reverse iterator pointing to the first element of the reversed span.
 
constexpr reverse_iterator rend () const noexcept
 Get a reverse iterator pointing to the last element of the reversed span.
 
constexpr reference front () const noexcept
 Access the first element of the span.
 
constexpr reference back () const noexcept
 Access the last element of the span.
 
constexpr reference operator[] (size_type idx) const noexcept
 Access the element at index idx.
 
constexpr size_type size () const noexcept
 Returns the number of elements in the Span.
 
constexpr size_type size_bytes () const noexcept
 Return the number of bytes occupied by the elements in the Span.
 
constexpr bool empty () const noexcept
 Check if the Span is empty.
 
constexpr Span first (size_type count) const
 Obtain a span that is a view over the first count elements of the span.
 
constexpr Span last (size_type count) const
 Obtain a span that is a view over the last count elements of the span.
 
constexpr Span subspan (size_type offset, size_type count) const
 Obtain a span that is a view over the span elements in the range [offset, offset + count).
 

Protected Attributes

pointer _ptr
 Pointer to the data referred to by Span.
 
size_type _size
 Number of elements of type T referred to by Span.
 

Detailed Description

template<typename T>
class kamping::Span< T >

A span modeled after C++20's std::span.

Since KaMPIng needs to be C++17 compatible and std::span is part of C++20, we need our own implementation of the above-described functionality.

Template Parameters
Ttype for which the span is defined.

Member Typedef Documentation

◆ reverse_iterator

template<typename T >
using kamping::Span< T >::reverse_iterator
Initial value:
std::reverse_iterator<iterator>

The type of a reverse iterator to a single elements in the span.

Constructor & Destructor Documentation

◆ Span() [1/3]

template<typename T >
template<typename It >
constexpr kamping::Span< T >::Span ( It first,
size_type size )
inlineconstexpr

Constructor for a span from an iterator of type It and a size.

Parameters
firstIterator pointing to the first element of the span.
sizeThe number of elements in the span.
Template Parameters
ItThe iterator type.

◆ Span() [2/3]

template<typename T >
template<typename It >
constexpr kamping::Span< T >::Span ( It first,
It last )
inlineconstexpr

Constructs a span that is a view over the range [first, last); the resulting span has data() == kamping::internal::to_address(first) and size() == last-first.

If [first, last) is not a valid range, or if It does not model a C++20 contiguous iterator, the behavior is undefined. This is analogous to the behavior of std::span.

Parameters
firstbegin iterator of the range
lastend iterator of the range
Template Parameters
Itthe iterator type.

◆ Span() [3/3]

template<typename T >
template<typename Range >
constexpr kamping::Span< T >::Span ( Range && range)
inlineconstexpr

Constructs a span that is a view over the range range. The resulting span has data() == std::data(range) and size() == std::size().

If range does not model a C++20 contiguous range, the behavior is undefined. This is analogous to the behavior of std::span.

Parameters
rangeThe range.
Template Parameters
RangeThe range type.

Member Function Documentation

◆ begin()

template<typename T >
constexpr iterator kamping::Span< T >::begin ( ) const
inlineconstexprnoexcept

Get iterator pointing to the first element of the span.

Returns
Iterator pointing to the first element of the span.

◆ data()

template<typename T >
constexpr pointer kamping::Span< T >::data ( ) const
inlineconstexprnoexcept

Get access to the underlying memory.

Returns
Pointer to the underlying memory.

◆ empty()

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

Check if the Span is empty.

Returns
true if the Span is empty, false otherwise.

◆ end()

template<typename T >
constexpr iterator kamping::Span< T >::end ( ) const
inlineconstexprnoexcept

Get iterator pointing past the last element of the span.

Returns
Iterator pointing past the last element of the span.

◆ size()

template<typename T >
constexpr size_type kamping::Span< T >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the Span.

Returns
Number of elements in the span.

◆ size_bytes()

template<typename T >
constexpr size_type kamping::Span< T >::size_bytes ( ) const
inlineconstexprnoexcept

Return the number of bytes occupied by the elements in the Span.

Returns
The number of elements in the span times the number of bytes per element.

◆ subspan()

template<typename T >
constexpr Span kamping::Span< T >::subspan ( size_type offset,
size_type count ) const
inlineconstexpr

Obtain a span that is a view over the span elements in the range [offset, offset + count).

Parameters
offsetThe offset of the first element of the span.
countThe number of elements in the span.

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