Lumiera  0.pre.03
»edit your freedom«
null-value.hpp File Reference

Go to the source code of this file.

Description

Singleton-style holder for NIL or default values.

This template allows to maintain a "Null Object" value, with type-based access. It is implemented as a cluster of Meyer's Singletons, thus the creation happens on demand, and the destruction happens "sometime" during application shutdown. Contrary to the generic lumiera Singleton holder, this implementation is lightweight and without any further prerequisites and validity checks.

Warning
we can't make any assumptions regarding the exact time when the dtor is called, and it is even impossible to detect if this happened already. Any access after that point will use a defunct object, thus the user needs to assure this facility is never used during application shutdown

purpose of NIL objects

Employing the NIL object pattern instead of NULL pointers typically leads to greatly simplified and more robust code. Usually the only problem is these NIL marker objects need to exist somewhere. In case no factory is used for object creation, this NullValue holder might satisfy this need.

NIL objects are assumed to be default constructible for now. Initialisation may introduce a race, which is considered acceptable here, as these objects are assumed to be simple, constant and value-like.

Note
deliberately this template is an extension point for explicit specialisation
Todo:
initialisation could be extended to use a free function to fabricate the NIL value object, so to support the special case of an NIL object not being default constructible
See also
null-value-test.cpp
lib::advice::Request usage example

Definition in file null-value.hpp.

Classes

struct  NullValue< TY >
 Singleton holder for NIL or default value objects. More...
 

Namespaces

 lib
 Implementation namespace for support and library code.