userver: utils::AnyMovable Class Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
utils::AnyMovable Class Referencefinal

Replacement for std::any that is not copyable. It allows to store non-copyable and even non-movable types. More...

#include <userver/utils/any_movable.hpp>

Classes

struct  HolderBase
 

Public Member Functions

constexpr AnyMovable () noexcept=default
 Creates an empty AnyMovable
 
 AnyMovable (AnyMovable &&) noexcept=default
 AnyMovable is movable, but not copyable
 
AnyMovableoperator= (AnyMovable &&) noexcept=default
 
template<typename ValueType , typename = std::enable_if_t<!std::is_same_v< AnyMovable, std::decay_t<ValueType>>>>
 AnyMovable (ValueType &&value)
 
template<typename ValueType , typename... Args>
 AnyMovable (std::in_place_type_t< ValueType > tag, Args &&... args)
 In-place constructs an object of the specified type.
 
template<typename ValueType , typename Item , typename... Args>
 AnyMovable (std::in_place_type_t< ValueType > tag, std::initializer_list< Item > list, Args &&... args)
 In-place constructs an object of the specified type.
 
template<typename ValueType >
AnyMovableoperator= (ValueType &&rhs)
 
bool HasValue () const noexcept
 Check if the AnyMovable is empty.
 
void Reset () noexcept
 Destroy the old contents, making *this empty.
 
template<typename ValueType , typename... Args>
void Emplace (Args &&... args)
 In-place constructs an object of the specified type.
 
template<typename ValueType , typename Item , typename... Args>
void Emplace (std::initializer_list< Item > list, Args &&... args)
 In-place constructs an object of the specified type.
 

Friends

template<typename ValueType >
ValueType * AnyCast (AnyMovable *) noexcept
 
template<typename ValueType >
const ValueType * AnyCast (const AnyMovable *) noexcept
 

Detailed Description

Replacement for std::any that is not copyable. It allows to store non-copyable and even non-movable types.

Usage example:

Definition at line 24 of file any_movable.hpp.

Constructor & Destructor Documentation

◆ AnyMovable() [1/3]

template<typename ValueType , typename >
utils::AnyMovable::AnyMovable ( ValueType &&  value)

Copies or moves the provided object inside the AnyMovable. const, reference, arrays and function pointers are decayed.

Definition at line 153 of file any_movable.hpp.

◆ AnyMovable() [2/3]

template<typename ValueType , typename... Args>
utils::AnyMovable::AnyMovable ( std::in_place_type_t< ValueType >  tag,
Args &&...  args 
)
explicit

In-place constructs an object of the specified type.

Definition at line 164 of file any_movable.hpp.

◆ AnyMovable() [3/3]

template<typename ValueType , typename Item , typename... Args>
utils::AnyMovable::AnyMovable ( std::in_place_type_t< ValueType >  tag,
std::initializer_list< Item list,
Args &&...  args 
)
explicit

In-place constructs an object of the specified type.

Definition at line 168 of file any_movable.hpp.

Member Function Documentation

◆ Emplace() [1/2]

template<typename ValueType , typename... Args>
void utils::AnyMovable::Emplace ( Args &&...  args)

In-place constructs an object of the specified type.

Definition at line 179 of file any_movable.hpp.

◆ Emplace() [2/2]

template<typename ValueType , typename Item , typename... Args>
void utils::AnyMovable::Emplace ( std::initializer_list< Item list,
Args &&...  args 
)

In-place constructs an object of the specified type.

Definition at line 184 of file any_movable.hpp.

◆ operator=()

template<typename ValueType >
AnyMovable & utils::AnyMovable::operator= ( ValueType &&  rhs)

Copies or moves the provided object inside the AnyMovable. const, reference, arrays and function pointers are decayed.

Definition at line 173 of file any_movable.hpp.

Friends And Related Symbol Documentation

◆ AnyCast [1/2]

template<typename ValueType >
ValueType * AnyCast ( AnyMovable operand)
friend
Returns
nullptr if operand is nullptr or type of the data stored in operand does not match ValueType

Definition at line 189 of file any_movable.hpp.

◆ AnyCast [2/2]

template<typename ValueType >
const ValueType * AnyCast ( const AnyMovable operand)
friend
Returns
nullptr if operand is nullptr or type of the data stored in operand does not match ValueType

Definition at line 194 of file any_movable.hpp.


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