Lumiera  0.pre.03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
access-casted.hpp File Reference

Go to the source code of this file.


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>


struct  AccessCasted< TAR >
 Helper template to access a given value, possibly converted or casted in a safe way. More...