Bayes Filters Library
Classes | Public Member Functions | Private Attributes | Friends | List of all members
bfl::any::any Class Reference

The class any describes a type-safe container for single values of any type. More...

#include <any.h>

Classes

class  holder
 
class  placeholder
 

Public Member Functions

 any () noexcept
 Constructs an empty object. More...
 
 any (const any &other)
 Copies content of other into a new instance, so that any content is equivalent in both type and value to those of other prior to the constructor call, or empty if other is empty. More...
 
 any (any &&other) noexcept
 Moves content of other into a new instance, so that any content is equivalent in both type and value to those of other prior to the constructor call, or empty if other is empty. More...
 
template<typename ValueType >
 any (const ValueType &value)
 Constructs an object with initial content an object of type std::decay_t<ValueType>, direct-initialized from std::forward<ValueType>(value). More...
 
template<typename ValueType >
 any (ValueType &&value, typename std::enable_if<!std::is_same< any &, ValueType >::value >::type *=nullptr, typename std::enable_if<!std::is_const< ValueType >::value >::type *=nullptr)
 Constructs an object with initial content an object of type std::decay_t<ValueType>, direct-initialized from std::forward<ValueType>(value). More...
 
anyoperator= (const any &rhs)
 Assigns contents to the contained value. More...
 
anyoperator= (any &&rhs) noexcept
 Assigns contents to the contained value. More...
 
template<class ValueType >
anyoperator= (ValueType &&rhs)
 Assigns contents to the contained value. More...
 
 ~any () noexcept
 Destruct the object. More...
 
void reset () noexcept
 If not empty, destroys the contained object. More...
 
anyswap (any &rhs) noexcept
 Swaps the content of two any objects. More...
 
bool has_value () const noexcept
 Checks whether the object contains a value. More...
 
const std::type_info & type () const noexcept
 Queries the contained type. More...
 

Private Attributes

placeholdercontent
 

Friends

template<typename ValueType >
ValueType * any_cast (any *operand) noexcept
 Performs type-safe access to the contained object. More...
 

Detailed Description

The class any describes a type-safe container for single values of any type.

An object of class any stores an instance of any type that satisfies the constructor requirements or is empty, and this is referred to as the state of the class any object. The stored instance is called the contained object. Two states are equivalent if they are either both empty or if both are not empty and if the contained objects are equivalent. The non-member any_cast functions provide type-safe access to the contained object.

Definition at line 77 of file any.h.

Constructor & Destructor Documentation

◆ any() [1/5]

bfl::any::any::any ( )
inlinenoexcept

Constructs an empty object.

Postconditions: this->empty().

Definition at line 85 of file any.h.

Referenced by operator=(), and reset().

◆ any() [2/5]

bfl::any::any::any ( const any other)
inline

Copies content of other into a new instance, so that any content is equivalent in both type and value to those of other prior to the constructor call, or empty if other is empty.

Throws: may fail with a std::bad_alloc exception or any exceptions arising from the copy constructor of the contained type.

Definition at line 98 of file any.h.

◆ any() [3/5]

bfl::any::any::any ( any &&  other)
inlinenoexcept

Moves content of other into a new instance, so that any content is equivalent in both type and value to those of other prior to the constructor call, or empty if other is empty.

Postconditions: other->empty()

Definition at line 110 of file any.h.

◆ any() [4/5]

template<typename ValueType >
bfl::any::any::any ( const ValueType &  value)
inline

Constructs an object with initial content an object of type std::decay_t<ValueType>, direct-initialized from std::forward<ValueType>(value).

If std::is_copy_constructible<std::decay_t<ValueType>>::value is false, the program is ill-formed.

Throws: std::bad_alloc or any exceptions arising from the copy constructor of the contained type.

Definition at line 125 of file any.h.

◆ any() [5/5]

template<typename ValueType >
bfl::any::any::any ( ValueType &&  value,
typename std::enable_if<!std::is_same< any &, ValueType >::value >::type = nullptr,
typename std::enable_if<!std::is_const< ValueType >::value >::type = nullptr 
)
inline

Constructs an object with initial content an object of type std::decay_t<ValueType>, direct-initialized from std::forward<ValueType>(value).

If std::is_copy_constructible<std::decay_t<ValueType>>::value is false, the program is ill-formed.

Throws: std::bad_alloc or any exceptions arising from the copy constructor of the contained type.

Definition at line 138 of file any.h.

◆ ~any()

bfl::any::any::~any ( )
inlinenoexcept

Destruct the object.

Definition at line 203 of file any.h.

References content.

Member Function Documentation

◆ has_value()

bool bfl::any::any::has_value ( ) const
inlinenoexcept

Checks whether the object contains a value.

Returns
true if instance contains a value, otherwise false.

Definition at line 235 of file any.h.

References content.

◆ operator=() [1/3]

any& bfl::any::any::operator= ( any &&  rhs)
inlinenoexcept

Assigns contents to the contained value.

Assigns by moving the state of rhs, as if by any(std::move(rhs)).swap(*this). rhs is left in a valid but unspecified state after the assignment.

Postconditions: rhs->empty()

Parameters
rhsobject whose contained value to assign

Definition at line 168 of file any.h.

References any(), and swap().

Here is the call graph for this function:

◆ operator=() [2/3]

any& bfl::any::any::operator= ( const any rhs)
inline

Assigns contents to the contained value.

Assigns by copying the state of rhs, as if by any(rhs).swap(*this).

Throws: std::bad_alloc or any exceptions arising from the copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.

Parameters
rhsobject whose contained value to assign

Definition at line 152 of file any.h.

References any().

Here is the call graph for this function:

◆ operator=() [3/3]

template<class ValueType >
any& bfl::any::any::operator= ( ValueType &&  rhs)
inline

Assigns contents to the contained value.

Assigns the type and value of rhs, as if by any(std::forward<ValueType>(rhs)).swap(*this). This overload only participates in overload resolution if std::decay_t<ValueType> is not the same type as any and std::is_copy_constructible_v<std::decay_t<ValueType>> is true.

Throws: std::bad_alloc or any exceptions arising from the move or copy constructor of the contained type. Assignment satisfies the strong guarantee of exception safety.

Parameters
rhsobject whose contained value to assign

Definition at line 192 of file any.h.

References any().

Here is the call graph for this function:

◆ reset()

void bfl::any::any::reset ( )
inlinenoexcept

If not empty, destroys the contained object.

Definition at line 212 of file any.h.

References any().

Here is the call graph for this function:

◆ swap()

any& bfl::any::any::swap ( any rhs)
inlinenoexcept

Swaps the content of two any objects.

Parameters
otherobject to swap with

Definition at line 223 of file any.h.

References content, and bfl::any::swap().

Referenced by operator=(), and bfl::any::swap().

Here is the call graph for this function:

◆ type()

const std::type_info& bfl::any::any::type ( ) const
inlinenoexcept

Queries the contained type.

The typeid of the contained value if instance is non-empty, otherwise typeid(void).

Definition at line 246 of file any.h.

References content, and bfl::any::any::placeholder::type().

Referenced by bfl::any::any_cast().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ any_cast

template<typename ValueType >
ValueType* any_cast ( any operand)
friend

Performs type-safe access to the contained object.

Throws blf::any::bad_any_cast if the typeid of the requested ValueType does not match that of the contents of operand.

Parameters
operandtarget any object

Definition at line 352 of file any.h.

Member Data Documentation

◆ content

placeholder* bfl::any::any::content
private

Definition at line 307 of file any.h.

Referenced by has_value(), swap(), type(), and ~any().


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