Lumiera  0.pre.03
access-casted-o.hpp File Reference

Go to the source code of this file.


Helper for accessing a value, employing either 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), but the actual implementation is chosen using std::type_traits. If no sensible implementation can be selected, EmptyVal<TAR>::create() is invoked instead, which by default creates a NULL value or similar by using the no-argument ctor of the type TAR. Alternatively, you may define an specialisation of EmptyVal, e.g. throwing an exception instead of creating a NULL value.

This is the obsoleted old version: It was excessively permissive, which I've learned to view as a danger, since it encourages a sloppy programming style.
See also
lumiera::WrapperPtr usage example to access a variant record
lib::InPlaceAnyHolder usage example to access a subclass in embedded storage

Definition in file access-casted-o.hpp.

#include <type_traits>


struct  AccessCasted_O< TAR >
struct  NullAccessor< RET >