PLCnext API Documentation 25.0.2.69
Classes | Public Types | Public Member Functions | Friends | List of all members
Arp::Base::Core::propagate_const< T > Class Template Reference

Encapsulates a (smart) pointer to ensure const-correctness even on pointer. More...

#include <propagate_const.hxx>

Public Types

using element_type = typename std::pointer_traits< T >::element_type
 Type of the object pointed to by T
 

Public Member Functions

constexpr propagate_const ()=default
 Creates object pointing to nullptr
 
 propagate_const (const propagate_const &other)=delete
 Copy constructor
 
constexpr propagate_const (propagate_const &&other) noexcept=default
 Move constructor
 
template<class U , class = std::enable_if_t < std::is_constructible_v < T, U && >>>
constexpr propagate_const (propagate_const< U > &&other)
 Construct from a propagate_const object of compatible type
 
template<class U , class = std::enable_if_t < std::is_constructible_v < T, U && > && !is_propagate_const<std::decay_t<U>>::value >>
constexpr propagate_const (U &&other)
 Construct from an object of compatible type More...
 
propagate_constoperator= (const propagate_const &other)=delete
 Copy assignment operator
 
propagate_constoperator= (propagate_const &&other) noexcept=default
 Move assignment operator
 
template<class U , class = std::enable_if_t<std::is_convertible_v<U, T>>>
propagate_constoperator= (propagate_const< U > &&other)
 Move assign from a propagate_const object of compatible type
 
template<class U , class = std::enable_if_t < std::is_convertible_v<U, T>&& !is_propagate_const<std::decay_t<U>>::value >>
propagate_constoperator= (U &&other)
 Assignment from an object of compatible type More...
 
void swap (propagate_const &other) noexcept
 Swaps the contents of this and other More...
 
element_typeget ()
 Returns a raw pointer to the pointee
 
const element_typeget () const
 Returns a const raw pointer to the pointee
 
 operator bool () const
 Checks whether the pointee is not equal to nullptr
 
element_typeoperator* ()
 Returns a reference to the pointee
 
const element_typeoperator* () const
 Returns a const reference to the pointee
 
element_typeoperator-> ()
 Returns a raw pointer to the pointee
 
const element_typeoperator-> () const
 Returns a const raw pointer to the pointee
 
template<class T_ = T, class U = std::enable_if_t<std::is_convertible_v<const T_, const element_type*>>>
 operator element_type * ()
 Implicit conversion to the element type More...
 
template<class T_ = T, class U = std::enable_if_t<std::is_convertible_v<const T_, const element_type*>>>
 operator const element_type * () const
 Implicit conversion to the element type More...
 

Friends

constexpr bool operator== (const propagate_const &lhs, std::nullptr_t)
 Equality comparison with nullptr
 
constexpr bool operator== (std::nullptr_t, const propagate_const &rhs)
 Equality comparison with nullptr
 
constexpr bool operator!= (const propagate_const &lhs, std::nullptr_t)
 Equality comparison with nullptr
 
constexpr bool operator!= (std::nullptr_t, const propagate_const &rhs)
 Equality comparison with nullptr
 
template<class U >
constexpr bool operator== (const propagate_const &lhs, const propagate_const< U > &rhs)
 Equality comparison with other propagate_const object
 
template<class U >
constexpr bool operator!= (const propagate_const &lhs, const propagate_const< U > &rhs)
 Equality comparison with other propagate_const object
 
template<class U >
constexpr bool operator== (const propagate_const &lhs, const U &rhs)
 Equality comparison with underlying object type
 
template<class U >
constexpr bool operator!= (const propagate_const &lhs, const U &rhs)
 Equality comparison with underlying object type
 
template<class U >
constexpr bool operator== (const U &lhs, const propagate_const &rhs)
 Equality comparison with underlying object type
 
template<class U >
constexpr bool operator!= (const U &lhs, const propagate_const &rhs)
 Equality comparison with underlying object type
 

Detailed Description

template<class T>
class Arp::Base::Core::propagate_const< T >

Encapsulates a (smart) pointer to ensure const-correctness even on pointer.

Usually smart pointers behave like raw pointers. When embedding them in a class it is possible to call non-const members of the pointee from const members of the surrounding class. By wrapping a pointer or smart pointer in propagate_const const-correctness can be ensured with almost no overhead.

Template Parameters
TThe type to propagate const for. The type T shall either be a raw pointer or a smart pointer providing the get() operation.

Constructor & Destructor Documentation

◆ propagate_const()

template<class T >
template<class U , class = std::enable_if_t < std::is_constructible_v < T, U && > && !is_propagate_const<std::decay_t<U>>::value >>
constexpr Arp::Base::Core::propagate_const< T >::propagate_const ( U &&  other)
inlineexplicitconstexpr

Construct from an object of compatible type

Parameters
otherInitializer of underlying object

Member Function Documentation

◆ operator const element_type *()

template<class T >
template<class T_ = T, class U = std::enable_if_t<std::is_convertible_v<const T_, const element_type*>>>
Arp::Base::Core::propagate_const< T >::operator const element_type * ( ) const
inline

Implicit conversion to the element type

Only available if T supports the conversion.

◆ operator element_type *()

template<class T >
template<class T_ = T, class U = std::enable_if_t<std::is_convertible_v<const T_, const element_type*>>>
Arp::Base::Core::propagate_const< T >::operator element_type * ( )
inline

Implicit conversion to the element type

Only available if T supports the conversion.

◆ operator=()

template<class T >
template<class U , class = std::enable_if_t < std::is_convertible_v<U, T>&& !is_propagate_const<std::decay_t<U>>::value >>
propagate_const & Arp::Base::Core::propagate_const< T >::operator= ( U &&  other)
inline

Assignment from an object of compatible type

Parameters
otherAssignee of underlying object

◆ swap()

template<class T >
void Arp::Base::Core::propagate_const< T >::swap ( propagate_const< T > &  other)
inlinenoexcept

Swaps the contents of this and other

Parameters
otherObject to swap the contents with

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