Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
item-wrapper.hpp File Reference

Adapter to store and hold an element of arbitrary type in local storage. More...

Go to the source code of this file.

Description

Adapter to store and hold an element of arbitrary type in local storage.

Notably, the difference between values and references can be levelled, while default construction or copy abilities are passed through. Such an inline container can be relevant for generic programming, especially to capture the result of an arbitrary function. This container can be created empty (which requires to store an additional state flag); the stored payload can be accessed through the dereferentiation operator (similar to a smart-ptr or to std::optional). The interface was shaped by its primary use case, which is to bind transforming functors into a processing pipeline, or for caching the result of a computation. Another use case is to circumvent the finiteness of references, to re-bind them to another target, or to replace an immutable object.

Note
the essential trait is that for each usage we have static, compile-time knowledge of the precise type with all its adornments, while we can not assume anything about this type when writing the code, to allow for maximum flexibility of potential usages. Contrast this to the pattern of type erasure, where we discard specific knowledge after construction; for such cases, opaque-holder.hpp might be a better fit.
See also
lib::TransformIter
lib::explore

Definition in file item-wrapper.hpp.

#include "lib/error.hpp"
#include "lib/nocopy.hpp"
#include "lib/util.hpp"
#include <cstddef>
#include <utility>
#include <type_traits>

Namespaces

namespace  lib
 Implementation namespace for support and library code.
 
namespace  lib::wrapper
 

Classes

class  ItemWrapper< TY >
 Universal value/ref wrapper accessible similar to a pointer. More...
 
class  ItemWrapper< TY & >
 Specialisation of the ItemWrapper to deal with references, as if they were pointer values. More...
 
class  ItemWrapper< void >
 Fallback-specialisation for ItemWrapper<void>. More...
 

Functions

template<typename TY >
bool operator== (ItemWrapper< TY > const &w1, ItemWrapper< TY > const &w2)
 allow equality comparison if the wrapped types are comparable
 
template<typename TY >
bool operator!= (ItemWrapper< TY > const &w1, ItemWrapper< TY > const &w2)