Lumiera  0.pre.03
»edit your freedom«
replaceable-item.hpp File Reference

Go to the source code of this file.

Description

Adapter wrapper to treat non-assignable values as if they were assignable.

Prerequisite is for the type to be copy constructible (maybe even just move constructible). The typical usage is when we want to take a snapshot from some value, but do not actually need the ability to assign something to a specific object instance. In such a situation, we may just destroy a previous snapshot and then place a new copy initialised value into the same storage space. For all really assignable types we fall back to a trivial implementation.

motivation
The typical usage is in library or framework code, where we do not know what types to expect. For example, the Lumiera command framework automatically captures an UNDO memento based on the return type of a state capturing function. It would be highly surprising for the user if it wasn't possible to capture e.g. time values or durations as old state, because these entities can not be re-assigned with new values, only created. But obviously a command handling framework needs the ability to capture state consecutively several times, and this adapter was created to bridge this conceptual discrepancy
extensions
  • the type can be solely move constructible, in which case the payload needs to be moved explicitly when embedding into this adapter ///////////////////////////////////////////////TICKET 1059 : does not work yet on GCC-4.9
  • when the payload is equality comparable, the container is as well, by delegation
  • container instances can be default created, which emplaces an empty value. The actual value to embed is retrieved from the lib::NullValue template, which is a static per-type singleton.
  • thus types which are not even default constructible can still be used, by providing an explicit specialisation of lib::NullValue for this type.
See also
ReplaceableIterm_test
steam::control::MementoTie

Definition in file replaceable-item.hpp.

#include "lib/error.hpp"
#include "lib/null-value.hpp"
#include "lib/meta/util.hpp"
#include "lib/util.hpp"
#include <type_traits>
#include <utility>
#include <cstddef>

Classes

struct  is_assignable_value< X >
 
class  ReplaceableItem< X, COND >
 Adapter container to take snapshots from non-assignable values. More...
 
class  ReplaceableItem< X, meta::enable_if< is_assignable_value< X > > >
 simple delegating implementation to use for regular cases More...
 
class  ReplaceableItem< X, meta::enable_if< std::is_reference< X > > >
 disallow embedding references More...
 

Functions

template<typename X >
bool operator!= (ReplaceableItem< X > const &li, ReplaceableItem< X > const &ri)
 
template<typename X , typename Z >
bool operator!= (ReplaceableItem< X > const &item, Z const &something)
 
template<typename Z , typename X >
bool operator!= (Z const &something, ReplaceableItem< X > const &item)
 
template<typename X >
bool operator== (ReplaceableItem< X > const &li, ReplaceableItem< X > const &ri)
 
template<typename X , typename Z >
bool operator== (ReplaceableItem< X > const &item, Z const &something)
 
template<typename Z , typename X >
bool operator== (Z const &something, ReplaceableItem< X > const &item)
 

Namespaces

 lib
 Implementation namespace for support and library code.