Lumiera  0.pre.03
»edit your freedom«
ItemWrapper< TY > Class Template Reference

#include "lib/wrapper.hpp"

Description

template<typename TY>
class lib::wrapper::ItemWrapper< TY >

Universal value/ref wrapper accessible similar to a pointer.

A copyable, assignable value object to hold a given value within an embedded inline buffer. It can be default constructed and bool evaluated to detect an empty holder. The value is retrieved through a pointer-like interface, by explicit dereferentiation. (Contrast this to std::ref, where the original reference is retrieved by conversion).

Note
when the embedded value is a pointer, ItemWrapper does not take ownership of and manage data the pointer is pointing to.

The purpose of this template is to be able to remember pretty much any kind of value or pointer or reference, and to subsume this handling within a single template. An example would be to remember the value yielded by a function, without any further assumptions regarding this function.

Definition at line 102 of file wrapper.hpp.

Public Member Functions

 ItemWrapper (TY const &o)
 
 ItemWrapper (TY &&ro)
 
 ItemWrapper (ItemWrapper const &ref)
 
 ItemWrapper (ItemWrapper &&rref)
 
ItemWrapperdefaultInit ()
 implant a default-initialised instance of the payload type
 
bool isValid () const
 
 operator bool () const
 
TY & operator* () const
 
TY * operator-> () const
 
ItemWrapperoperator= (ItemWrapper const &cref)
 
ItemWrapperoperator= (ItemWrapper &ref)
 
ItemWrapperoperator= (ItemWrapper &&rref)
 
template<typename X >
ItemWrapperoperator= (X &&something)
 Emulate »assignment« by discarding and then construction of a new payload. More...
 
void reset ()
 

Private Types

using TY_unconst = std::remove_const_t< TY >
 

Private Member Functions

TY & access () const
 
TY_unconst & access_unconst () const
 < used to assign new buffer contents
 
template<typename REF >
void build (REF &&ref)
 
void discard ()
 

Private Attributes

std::byte content_ [sizeof(TY)]
 
bool created_
 

Member Function Documentation

◆ operator=()

ItemWrapper& operator= ( X &&  something)
inline

Emulate »assignment« by discarding and then construction of a new payload.

Parameters
somethingfrom which TY can be (copy/move)constructed
Remarks
allows handling »move-only« types; for the typical use case, something new is fabricated in a lambda and then moved into the ItemWrapper; thus the performance overhead of destroy/re-created is not deemed relevant. SFINAE tricks on hidden/deleted assignment operator can be unreliable.

Definition at line 221 of file wrapper.hpp.

+ Inheritance diagram for ItemWrapper< TY >:
+ Collaboration diagram for ItemWrapper< TY >:

The documentation for this class was generated from the following file: