Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
 

Function Documentation

◆ captureRawAddrOffset()

ptrdiff_t captureRawAddrOffset ( RawAddr  anchor,
RawAddr  subject 
)
inline

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

References captureRawAddrOffset().

Referenced by captureRawAddrOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ relocate()

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

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

References relocate().

Referenced by relocate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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);
}()
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
void const * RawAddr
Definition lazy-init.hpp:92
bool isCloseBy(A &&a, B &&b, size_t consideredNearby=50)
determine heuristically if two objects are located „close to each other“ in memory.
Definition util.hpp:434

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 126 of file lazy-init.hpp.