Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
access-casted.hpp File Reference

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). More...

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
Warning
to state the obvious — usage of such a facility raises questions...

Definition in file access-casted.hpp.

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

Namespaces

namespace  util
 
namespace  util::anonymous_namespace{access-casted.hpp}
 

Typedefs

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

Classes

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