11#include <ext/typeindex>
12#include <ext/typeinfo>
17template <
class Type >
19 std::optional < std::decay_t < Type > > m_data;
25 m_data = std::move (
const_cast < Type &&
> ( data ) );
29 return std::move ( m_data.value ( ) );
33template <
class Type >
35 std::optional < std::reference_wrapper < Type > > m_data;
41 m_data = std::reference_wrapper < Type > (
const_cast < Type &
> ( data ) );
45 return std::move ( m_data->get ( ) );
49template <
class Type >
50class ValueHolder :
public std::conditional_t < std::is_reference_v < Type >, ReferenceImpl < std::decay_t < Type > >, ValueImpl < std::decay_t < Type > > > {
54 return abstraction::TypeQualifiers::typeQualifiers < Type > ( );
61 bool isTemporary ( )
const override {
65 std::shared_ptr < abstraction::Value > asValue (
bool move,
bool temporary )
override {
69 if constexpr ( std::is_abstract_v < std::decay_t < Type > > )
70 throw std::domain_error (
"Cannot declare value of abstract class." );
71 else if constexpr ( ! std::is_assignable_v < std::decay_t < Type > &, std::decay_t < Type > > )
72 throw std::domain_error (
"Cannot assign value." );
74 return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary );
80 throw std::domain_error (
"Lvalue references cannot be temporaries." );
82 this->setValue ( std::forward < Type > ( value ) );
Definition: ValueHolder.hpp:34
void setValue(const Type &data) override
Definition: ValueHolder.hpp:40
Type && getValue() override
Definition: ValueHolder.hpp:44
TypeQualifierSet
Definition: TypeQualifiers.hpp:15
static constexpr bool isLvalueRef(TypeQualifierSet arg)
Definition: TypeQualifiers.hpp:47
Definition: ValueHolderInterface.hpp:15
Definition: ValueHolder.hpp:50
ValueHolder(Type &&value, bool temporary)
Definition: ValueHolder.hpp:78
Definition: ValueHolder.hpp:18
void setValue(const Type &data) override
Definition: ValueHolder.hpp:24
Type && getValue() override
Definition: ValueHolder.hpp:28
Definition: typeindex.h:37
Definition: AlgorithmAbstraction.hpp:11
Type
Definition: MeasurementTypes.hpp:20