density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
Public Member Functions | List of all members
dynamic_reference< RUNTIME_TYPE, CV_QUALIFIER > Class Template Reference

#include <dynamic_reference.h>

Public Member Functions

 dynamic_reference ()=delete
 
template<typename TARGET_TYPE >
 dynamic_reference (TARGET_TYPE &i_target_object)
 
constexpr dynamic_reference (const RUNTIME_TYPE &i_target_type, add_cv_qual_t< void, CV_QUALIFIER > *i_target_address)
 
template<cv_qual OTHER_CV>
constexpr dynamic_reference (const dynamic_reference< RUNTIME_TYPE, OTHER_CV > &i_source)
 
dynamic_referenceoperator= (const dynamic_reference &i_source)=delete
 
constexpr const RUNTIME_TYPE & type () const noexcept
 
constexpr add_cv_qual_t< void, CV_QUALIFIER > * address () const noexcept
 
template<typename TYPE >
constexpr bool is () const noexcept
 
template<typename TYPE >
DENSITY_CPP14_CONSTEXPR add_cv_qual_t< TYPE, CV_QUALIFIER > & as () const noexcept
 

Detailed Description

template<typename RUNTIME_TYPE, cv_qual CV_QUALIFIER>
class density::dynamic_reference< RUNTIME_TYPE, CV_QUALIFIER >

Holds a reference to an object whose type in unknown at compile time. This class template is an abstraction of a pair of void pointer and a runtime type.

Template Parameters
RUNTIME_TYPERuntime-type object used to store the actual complete type of the target object. This type must satisfy the requirements of RuntimeType. The default is runtime_type.
CV_QUALIFIERCV-qualification of the reference. The default is cv_qual::no_qual.

The convenience alias templates const_dynamic_reference, volatile_dynamic_reference and const_volatile_dynamic_reference constraint the cv_qual template parameter respectively to cv_qual::const_qual, cv_qual::volatile_qual and cv_qual::const_volatile_qual.

Constructor & Destructor Documentation

dynamic_reference ( )
delete

Deleted default constructor.

dynamic_reference ( TARGET_TYPE &  i_target_object)
inline

Constructs an instance of dynamic_reference bound to the specified target object.

This constructor is excluded from the overload set if the type of the target type is more cv-qualified than this specialization of dynamic_reference:

int i = 42;
dynamic_reference<RT> r1(i);
const_dynamic_reference<RT> r2(i);
int const ci = 42;
//dynamic_reference<RT> r3(ci); // <- error, would drop the const-ness
const_volatile_dynamic_reference<RT> r4(ci);
int volatile vi = 42;
//const_dynamic_reference<RT> r5(vi); // <- error, would drop the volatile-ness
const_volatile_dynamic_reference<RT> r6(vi);
// dynamic_reference is constructible from non-cv-qualified reference
static_assert(std::is_constructible<dynamic_reference<RT>, T&>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, const T&>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, volatile T&>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, const volatile T&>::value, "");
// const_dynamic_reference is constructible from non-volatile references
static_assert(std::is_constructible<const_dynamic_reference<RT>, T&>::value, "");
static_assert(std::is_constructible<const_dynamic_reference<RT>, const T&>::value, "");
static_assert(!std::is_constructible<const_dynamic_reference<RT>, volatile T&>::value, "");
static_assert(!std::is_constructible<const_dynamic_reference<RT>, const volatile T&>::value, "");
// volatile_dynamic_reference is constructible from non-const references
static_assert(std::is_constructible<volatile_dynamic_reference<RT>, T&>::value, "");
static_assert(!std::is_constructible<volatile_dynamic_reference<RT>, const T&>::value, "");
static_assert(std::is_constructible<volatile_dynamic_reference<RT>, volatile T&>::value, "");
static_assert(!std::is_constructible<volatile_dynamic_reference<RT>, const volatile T&>::value, "");
// const_volatile_dynamic_reference is constructible from any reference
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, T&>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, const T&>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, volatile T&>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, const volatile T&>::value, "");

Postcoditions: Given an object t, the following conditions hold:

dynamic_reference<RT, CV_QUAL> r(t);
assert(r.type() == RT::make<decltype(t)>() && r.address() == &t);

Throws: unspecified

constexpr dynamic_reference ( const RUNTIME_TYPE &  i_target_type,
add_cv_qual_t< void, CV_QUALIFIER > *  i_target_address 
)
inline

Constructs a dynamic_reference assigning a target object.

Postcoditions: Given an object t, the following conditions hold:

dynamic_reference<RT> r(RT::make<decltype(t)>(), &t);
assert(r.type() == RT::make<decltype(t)>() && r.address() == &t);

Throws: unspecified

constexpr dynamic_reference ( const dynamic_reference< RUNTIME_TYPE, OTHER_CV > &  i_source)
inline

Generalized copy constructor.

This constructor is excluded from the overload set if the argument is more cv-qualified than this dynamic_reference specialization:

int t = 1;
dynamic_reference<RT> r(t);
const_dynamic_reference<RT> r1(r); // <- ok
//dynamic_reference<RT> r2(r1); // <- error, would drop the const-ness
const_volatile_dynamic_reference<RT> r3(r1); // <- ok
// dynamic_reference is constructible from non-cv-qualified reference
static_assert(std::is_constructible<dynamic_reference<RT>, dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, const_dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, volatile_dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<dynamic_reference<RT>, const_volatile_dynamic_reference<RT>>::value, "");
// const_dynamic_reference is constructible from non-volatile references
static_assert(std::is_constructible<const_dynamic_reference<RT>, dynamic_reference<RT>>::value, "");
static_assert(std::is_constructible<const_dynamic_reference<RT>, const_dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<const_dynamic_reference<RT>, volatile_dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<const_dynamic_reference<RT>, const_volatile_dynamic_reference<RT>>::value, "");
// volatile_dynamic_reference is constructible from non-const references
static_assert(std::is_constructible<volatile_dynamic_reference<RT>, dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<volatile_dynamic_reference<RT>, const_dynamic_reference<RT>>::value, "");
static_assert(std::is_constructible<volatile_dynamic_reference<RT>, volatile_dynamic_reference<RT>>::value, "");
static_assert(!std::is_constructible<volatile_dynamic_reference<RT>, const_volatile_dynamic_reference<RT>>::value, "");
// const_volatile_dynamic_reference is constructible from any reference
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, dynamic_reference<RT>>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, const_dynamic_reference<RT>>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, volatile_dynamic_reference<RT>>::value, "");
static_assert(std::is_constructible<const_volatile_dynamic_reference<RT>, const_volatile_dynamic_reference<RT>>::value, "");

Postcoditions: Given an object r of a specialization of dynamic_reference, the following conditions hold:

auto r1 = r;
assert(r1.type() == r.type() && r1.address() == r.address());

Throws: unspecified

Member Function Documentation

dynamic_reference& operator= ( const dynamic_reference< RUNTIME_TYPE, CV_QUALIFIER > &  i_source)
delete

Deleted copy assignment.

constexpr const RUNTIME_TYPE& type ( ) const
inlinenoexcept

Returns a reference to the runtime type.

Throws: nothing

constexpr add_cv_qual_t<void, CV_QUALIFIER>* address ( ) const
inlinenoexcept

Returns the address of the target object. If the dynamic_reference is empty, the return value is nullptr.

Throws: nothing

constexpr bool is ( ) const
inlinenoexcept

Returns whether the target type is bound to the provided compile-time type and TYPE is not less cv-qualified than this specialization of dynamic_reference.

Example:

int t = 1;
dynamic_reference<RT> r(t);
assert(r.is<int>());
assert(r.is<const int>());
const_dynamic_reference<RT> r1(t);
assert(!r1.is<int>());
assert(r1.is<const int>());
assert(r1.is<const volatile int>());

Throws: nothing

DENSITY_CPP14_CONSTEXPR add_cv_qual_t<TYPE, CV_QUALIFIER>& as ( ) const
inlinenoexcept

Returns a reference to the target object, assuming that the target type is bound to the provided compile-time type.

Precoditions: The behavior is undefined if any of these conditions is not satisfied:

Example:

int t = 1;
dynamic_reference<RT> r(t);
assert(r.as<int>() == 1);
assert(r.as<const int>() == 1);

Throws: nothing


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