siplasplas
A library for C++ reflection and introspection
cpp::AnyArg Class Reference

Represents a type erased function call argument. More...

#include <siplasplas/typeerasure/anyarg.hpp>

Public Member Functions

template<typename T , typename = std::enable_if_t< !std::is_same<std::decay_t<T>, cpp::ConstReferenceSimpleAny>::value && !std::is_same<std::decay_t<T>, cpp::ReferenceSimpleAny>::value >>
 AnyArg (T &&value)
 Initializes an AnyArg object with a given value.
 
 AnyArg (const cpp::ReferenceSimpleAny &reference)
 
 AnyArg (const cpp::ConstReferenceSimpleAny &reference)
 
template<typename T >
const T & get () const
 Returns a const reference to the argument object. More...
 
template<typename T >
T & get ()
 Returns a reference to the argument object. More...
 
bool isRvalue () const
 Checks if the argument was an rvalue.
 
bool isLvalue () const
 Checks if the argument was an lvalue.
 
bool isConst () const
 Checks if the argument was const.
 

Detailed Description

Represents a type erased function call argument.

cpp::SimpleAny and cpp::Any classes represent type erased values that are owned by the any object, except explicitly stated by using Reference family of specializations. That means that when a normal any class is initialized with an lvalue, the value is copied into the any object. While this works for heterogeneous containers, that semantics doesn't fit the semantics expected on a function call, where parameters taking references alias existing objects.

AnyArg implements the semantics of a function call following two rules:

  • If the initializer value is an lvalue, AnyArg instance is a reference to the value. AnyArg objects are copyable.
  • If the initializer value is an rvalue, the initializer value is moved into the AnyArg. The AnyArg object owns the value. If the moved in value is not copyable, an exception is thrown when performing AnyArg copy. See cpp::features::Copyable.

Member Function Documentation

template<typename T >
const T& cpp::AnyArg::get ( ) const
inline

Returns a const reference to the argument object.

Template Parameters
TType of the argument (cv qualifiers and references are ignored). The behavior is undefined if T is not the original type of the argument
Returns
A const reference to the argument
template<typename T >
T& cpp::AnyArg::get ( )
inline

Returns a reference to the argument object.

Template Parameters
TType of the argument (cv qualifiers and references are ignored). The behavior is undefined if T is not the original type of the argument The behavior is also undefined if this get() overload is called and the argument is const lvalue reference (See isConst() and isLvalue())
Returns
A reference to the argument

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