Lumiera  0.pre.03
»edit your freedom«
access-casted.hpp File Reference

Go to the source code of this file.

Description

Helper for accessing a value, employing either a conversion or downcast, depending on the relation of the source type (type of the original value) and the target type (type we need within the usage context).

When instantiating AcessCasted<TAR>, we get a template static function AcessCasted<TAR>::access<SRC>(SRC&& elm), where the actual implementation is chosen using based on our type traits. If no sensible implementation can be selected, a static assertion will be triggered.

The possible conversion path is limited to options considered "safe"

  • automatic type conversions, as would happen when returning a value of type SRC from a function with return signature TAR
  • this possibly includes an up-cast from an implementation type to a base class
  • explicit copy construction when the type TAR is a plain value
  • downcast to implementation class only when a safe dynamic downcast can be performed, based on RTTI in the actual object.
  • additionally, a pointer will be formed by taking an address
  • and a reference will be initialised by dereferencing a pointer (with NULL check).
  • if valid and permitted by the rules of the language, r-value references and const values, references and pointers-to-const are supported as well.
See also
lib::InPlaceAnyHolder usage example to access a subclass in embedded storage

Definition in file access-casted.hpp.

#include "lib/error.hpp"
#include <type_traits>
#include <utility>

Classes

struct  AccessCasted< TAR >
 Helper template to access a given value, possibly converted or casted in a safe way. More...
 
struct  can_dereference< SRC, TAR >
 
struct  can_downcast< SRC, TAR >
 
struct  can_take_address< SRC, TAR >
 
struct  can_use_conversion< SRC, TAR >
 
struct  can_use_dynamic_downcast< SRC, TAR >
 
struct  has_RTTI< T >
 
struct  if_can_dereference< SRC, TAR >
 
struct  if_can_take_address< SRC, TAR >
 
struct  if_can_use_conversion< SRC, TAR >
 
struct  if_can_use_dynamic_downcast< SRC, TAR >
 

Typedefs

template<typename T >
using PlainType = typename remove_pointer< typename remove_reference< T >::type >::type
 

Namespaces