Class PolymorphicValue

Class Documentation

class PolymorphicValue

Container that passes Storable objects by value while preserving type.

This class is implicitly convertible to and from a reference to Storable, but behaves like a value: changing the internal Storable changes the object’s state, and copying the object creates a new Storable.

Note

While a PolymorphicValue is always initialized with a Storable, it may become empty if it is the source of a move-construction or move-assignment. Conversion of an empty value to Storable& throws.

Unnamed Group

PolymorphicValue(PolymorphicValue const &other)

Try to copy a PolymorphicValue.

Parameters
Exceptions
  • UnsupportedOperationException: Thrown if a copy is required and the object in other does not implement Storable::cloneStorable.

PolymorphicValue(PolymorphicValue &&other)

Unnamed Group

PolymorphicValue &operator=(PolymorphicValue const &other)

Try to assign a PolymorphicValue.

To preserve the run-time type of the object in other, this method swaps (and possibly copies) the Storables instead of relying on the Storable’s operator=.

Parameters
Exceptions
  • UnsupportedOperationException: Thrown if a copy is required and the object in other does not implement Storable::cloneStorable.

PolymorphicValue &operator=(PolymorphicValue &&other)
void swap(PolymorphicValue &other)

Exchange the contents of this container and another.

Unnamed Group

operator Storable&()

Return a reference to the internal Storable, if one exists.

Return

a reference to the internal object

Exceptions
  • pex::exceptions::LogicError: Thrown if this object is empty.

operator Storable const&() const
Storable &get()
Storable const &get() const

Unnamed Group

bool operator==(PolymorphicValue const &other) const

Test whether the contained Storables are equal.

Empty PolymorphicValues compare equal to each other and unequal to any non-empty PolymorphicValue.

bool operator!=(PolymorphicValue const &other) const

Public Functions

PolymorphicValue(Storable const &value)

Create a new object containing a copy of a Storable.

Parameters

~PolymorphicValue()
bool empty() const

Check whether this object contains a Storable.

Return

true if this object has no Storable, false otherwise

std::size_t hash_value() const

Return a hash of this object (optional operation).

Exceptions
  • UnsupportedOperationException: Thrown if the internal Storable is not hashable.

Related

void swap(PolymorphicValue &lhs, PolymorphicValue &rhs)

Swap specialization for PolymorphicValue.