template<class T>
Corrade::Containers::AnyReference class new in Git master

Lightweight non-owning l-value and r-value reference wrapper.

Combination of a Reference and MoveReference that accepts both l-value and r-value references. The main use case is for APIs that take a list of instances to optionally take over the ownership of — each instance remembers whether a l-value or a r-value reference was used to construct it and exposes that through isRvalue().

Like with MoveReference, use in a constexpr context is not envisioned for this class and so the API is not constexpr. There's no STL equivalent and thus no conversion interface from/to an external representation exists either.

Public types

using Type = T new in Git master
Value type.

Constructors, destructors, conversion operators

AnyReference(T& reference) noexcept
Construct from a l-value.
AnyReference(T&& reference) noexcept
Construct from a r-value.
template<class U, class = typename std::enable_if<std::is_base_of<T, U>::value>::type>
AnyReference(AnyReference<U> other) noexcept
Construct a reference from another of a derived type.
operator T&() const
Underlying reference.
operator AnyReference<const T>() const

Public functions

auto get() const -> T&
Underlying reference.
auto isRvalue() const -> bool
Whether the underlying reference is r-value.
auto operator->() const -> T*
Access the underlying reference.
auto operator*() const -> T&
Access the underlying reference.

Function documentation

template<class T>
Corrade::Containers::AnyReference<T>::AnyReference(T& reference) noexcept

Construct from a l-value.

When this constructor is used, isRvalue() returns false.

template<class T>
Corrade::Containers::AnyReference<T>::AnyReference(T&& reference) noexcept

Construct from a r-value.

When this constructor is used, isRvalue() returns true.

template<class T> template<class U, class = typename std::enable_if<std::is_base_of<T, U>::value>::type>
Corrade::Containers::AnyReference<T>::AnyReference(AnyReference<U> other) noexcept

Construct a reference from another of a derived type.

Expects that T is a base of U. The isRvalue() state is copied from other unchanged.

template<class T>
Corrade::Containers::AnyReference<T>::operator AnyReference<const T>() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class T>
bool Corrade::Containers::AnyReference<T>::isRvalue() const

Whether the underlying reference is r-value.

Returns false if the reference was constructed using AnyReference(T&), true if using AnyReference(T&&).

template<class T>
T* Corrade::Containers::AnyReference<T>::operator->() const

Access the underlying reference.

get(), operator*()

template<class T>
T& Corrade::Containers::AnyReference<T>::operator*() const

Access the underlying reference.

template<class T> template<class T>
Utility::Debug& operator<<(Utility::Debug& debug, AnyReference<T> value)

Debug output operator.