open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
opcua::Span< T > Class Template Reference

#include <span.hpp>

Detailed Description

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

View to a contiguous sequence of objects, similar to std::span in C++20.

Spans are used to pass and return open62541 arrays without copy and to use them with the standard library algorithms. The view just holds two members: the pointer to T and the size, so it's lightweight and trivially copyable.

Template Parameters
TType of the array object, use const T for an immutable view
See also
https://en.cppreference.com/w/cpp/container/span
Examples
custom_datatypes/server_custom_datatypes.cpp, events/client_eventfilter.cpp, events/server_events.cpp, method/server_method.cpp, and typeconversion.cpp.

Definition at line 26 of file span.hpp.

Public Types

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

Public Member Functions

constexpr Span () noexcept=default
 
constexpr Span (T *data, size_t size) noexcept
 
template<typename Container , typename = EnableIfHasSizeAndData<Container>>
constexpr Span (Container &container) noexcept
 
template<typename Container , typename = EnableIfHasSizeAndData<Container>>
constexpr Span (const Container &container) noexcept
 
constexpr Span (std::initializer_list< value_type > values) noexcept
 
constexpr void swap (Span &other) noexcept
 
constexpr size_t size () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr pointer data () const noexcept
 
constexpr reference operator[] (size_t index) const noexcept
 
constexpr reference front () const noexcept
 
constexpr reference back () const noexcept
 
constexpr iterator begin () const noexcept
 
constexpr iterator end () const noexcept
 
constexpr const_iterator cbegin () const noexcept
 
constexpr const_iterator cend () const noexcept
 
constexpr reverse_iterator rbegin () const noexcept
 
constexpr reverse_iterator rend () const noexcept
 
constexpr const_reverse_iterator crbegin () const noexcept
 
constexpr const_reverse_iterator crend () const noexcept
 
constexpr Span subview (size_t offset, size_t count=(std::numeric_limits< std::size_t >::max)()) const noexcept
 
constexpr Span first (size_t count) const noexcept
 
constexpr Span last (size_t count) const noexcept
 

Member Typedef Documentation

◆ element_type

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

Definition at line 46 of file span.hpp.

◆ value_type

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

Definition at line 47 of file span.hpp.

◆ size_type

template<typename T >
using opcua::Span< T >::size_type = size_t

Definition at line 48 of file span.hpp.

◆ difference_type

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

Definition at line 49 of file span.hpp.

◆ pointer

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

Definition at line 50 of file span.hpp.

◆ const_pointer

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

Definition at line 51 of file span.hpp.

◆ reference

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

Definition at line 52 of file span.hpp.

◆ const_reference

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

Definition at line 53 of file span.hpp.

◆ iterator

template<typename T >
using opcua::Span< T >::iterator = pointer

Definition at line 54 of file span.hpp.

◆ const_iterator

template<typename T >
using opcua::Span< T >::const_iterator = const_pointer

Definition at line 55 of file span.hpp.

◆ reverse_iterator

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

Definition at line 56 of file span.hpp.

◆ const_reverse_iterator

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

Definition at line 57 of file span.hpp.

Constructor & Destructor Documentation

◆ Span() [1/5]

template<typename T >
opcua::Span< T >::Span ( )
constexprdefaultnoexcept

◆ Span() [2/5]

template<typename T >
opcua::Span< T >::Span ( T * data,
size_t size )
inlineconstexprnoexcept

Definition at line 62 of file span.hpp.

◆ Span() [3/5]

template<typename T >
template<typename Container , typename = EnableIfHasSizeAndData<Container>>
opcua::Span< T >::Span ( Container & container)
inlineconstexprnoexcept

Implicit constructor from a container like std::array or std::vector.

Definition at line 70 of file span.hpp.

◆ Span() [4/5]

template<typename T >
template<typename Container , typename = EnableIfHasSizeAndData<Container>>
opcua::Span< T >::Span ( const Container & container)
inlineconstexprnoexcept

Implicit constructor from a container like std::array or std::vector (const).

Definition at line 77 of file span.hpp.

◆ Span() [5/5]

template<typename T >
opcua::Span< T >::Span ( std::initializer_list< value_type > values)
inlineconstexprnoexcept

Implicit constructor from an initializer list.

Only safe to use if std::initializer_list itself outlives the Span:

void takeView(Span<const int> values);
// ok
takeView({1, 2, 3});
// not ok
Span<const int> values = {1, 2, 3};
takeView(values);
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26

Definition at line 93 of file span.hpp.

Member Function Documentation

◆ swap()

template<typename T >
void opcua::Span< T >::swap ( Span< T > & other)
inlineconstexprnoexcept

Definition at line 96 of file span.hpp.

◆ size()

template<typename T >
size_t opcua::Span< T >::size ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 101 of file span.hpp.

Referenced by opcua::AddNodesRequest::AddNodesRequest(), opcua::AddReferencesRequest::AddReferencesRequest(), opcua::Span< T >::back(), opcua::BrowseNextRequest::BrowseNextRequest(), opcua::BrowseRequest::BrowseRequest(), opcua::CallMethodRequest::CallMethodRequest(), opcua::CallRequest::CallRequest(), opcua::Span< T >::cend(), opcua::services::detail::createBrowsePath(), opcua::CreateMonitoredItemsRequest::CreateMonitoredItemsRequest(), opcua::DeleteMonitoredItemsRequest::DeleteMonitoredItemsRequest(), opcua::DeleteNodesRequest::DeleteNodesRequest(), opcua::DeleteReferencesRequest::DeleteReferencesRequest(), opcua::DeleteSubscriptionsRequest::DeleteSubscriptionsRequest(), opcua::Span< T >::empty(), opcua::Span< T >::end(), opcua::EnumDefinition::EnumDefinition(), opcua::EventFilter::EventFilter(), opcua::Span< T >::first(), opcua::Span< T >::last(), opcua::ModifyMonitoredItemsRequest::ModifyMonitoredItemsRequest(), opcua::Span< T >::operator[](), opcua::ReadRequest::ReadRequest(), opcua::RegisterNodesRequest::RegisterNodesRequest(), opcua::RelativePath::RelativePath(), opcua::SetMonitoringModeRequest::SetMonitoringModeRequest(), opcua::SetPublishingModeRequest::SetPublishingModeRequest(), opcua::SetTriggeringRequest::SetTriggeringRequest(), opcua::Span< T >::subview(), opcua::detail::toNativeArray(), opcua::TranslateBrowsePathsToNodeIdsRequest::TranslateBrowsePathsToNodeIdsRequest(), opcua::UnregisterNodesRequest::UnregisterNodesRequest(), and opcua::WriteRequest::WriteRequest().

◆ empty()

template<typename T >
bool opcua::Span< T >::empty ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 105 of file span.hpp.

Referenced by opcua::Span< T >::back(), and opcua::Span< T >::front().

◆ data()

◆ operator[]()

template<typename T >
reference opcua::Span< T >::operator[] ( size_t index) const
inlinenodiscardconstexprnoexcept

Definition at line 113 of file span.hpp.

◆ front()

template<typename T >
reference opcua::Span< T >::front ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 118 of file span.hpp.

◆ back()

template<typename T >
reference opcua::Span< T >::back ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 123 of file span.hpp.

◆ begin()

◆ end()

◆ cbegin()

template<typename T >
const_iterator opcua::Span< T >::cbegin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 136 of file span.hpp.

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

◆ cend()

template<typename T >
const_iterator opcua::Span< T >::cend ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 140 of file span.hpp.

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

◆ rbegin()

template<typename T >
reverse_iterator opcua::Span< T >::rbegin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 144 of file span.hpp.

◆ rend()

template<typename T >
reverse_iterator opcua::Span< T >::rend ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 148 of file span.hpp.

◆ crbegin()

template<typename T >
const_reverse_iterator opcua::Span< T >::crbegin ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 152 of file span.hpp.

◆ crend()

template<typename T >
const_reverse_iterator opcua::Span< T >::crend ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 156 of file span.hpp.

◆ subview()

template<typename T >
Span opcua::Span< T >::subview ( size_t offset,
size_t count = (std::numeric_limits<std::size_t>::max)() ) const
inlinenodiscardconstexprnoexcept

Obtain a view over count elements of this Span starting at offset offset.

Definition at line 161 of file span.hpp.

◆ first()

template<typename T >
Span opcua::Span< T >::first ( size_t count) const
inlinenodiscardconstexprnoexcept

Obtain a view over the first count elements of this Span.

Definition at line 174 of file span.hpp.

◆ last()

template<typename T >
Span opcua::Span< T >::last ( size_t count) const
inlinenodiscardconstexprnoexcept

Obtain a view over the last count elements of this Span.

Definition at line 182 of file span.hpp.