Lumiera  0.pre.03
»edit your freedom«
lib::anonymous_namespace{lazy-init.hpp} Namespace Reference

Functions

ptrdiff_t captureRawAddrOffset (RawAddr anchor, RawAddr subject)
 
template<class TAR >
static TAR * relocate (RawAddr anchor, ptrdiff_t offset)
 

Variables

const ptrdiff_t FUNCTOR_PAYLOAD_OFFSET
 

Variable Documentation

◆ FUNCTOR_PAYLOAD_OFFSET

const ptrdiff_t FUNCTOR_PAYLOAD_OFFSET
Initial value:
=
[]{
size_t slot{42};
std::function<RawAddr(void)> probe = [slot]{ return RawAddr(&slot); };
RawAddr functor = &probe;
RawAddr payload = probe();
if (not util::isCloseBy(functor, payload))
throw err::Fatal{"Unable to use lib::LazyInit because std::function does not "
"apply small-object optimisation with inline storage."};
return captureRawAddrOffset (functor,payload);
}()
HashVal slot(Query< asset::Pipe > const &query)
yield a suitable table slot for this query
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199

implementation defined : offset of a payload placed directly into a std::function when the small object optimisation applies.

Warning
relies on implementation behaviour not guaranteed by the standard, while supported by all known implementations today. This is exploited as a trick to allow for automatic late initialisation in a situation, were a functor needs to capture references.

Definition at line 135 of file lazy-init.hpp.

Referenced by LazyInit_test::verify_triggerMechanism().