Inheritance diagram for Deferrer:
Public Member Functions | |
Deferrer () | |
Constructor. | |
Deferrer & | operator= (const deferred_type &) |
Effectively builds the holded type. | |
operator T () const | |
Get back the holded type. | |
Protected Attributes | |
data_t | data |
A flat area of memory big enough to hold an instance of deferred_type. |
This class is designed to hold a instance of type T, without initializing it when the class is created. In fact, the construction of T is deferred to a later time, using operator=. This may be usefull when you want to equip a class with a constructor without arguments.
Using a Deferrer may be dangerous, e.g. when you make a call to the cast operator without having initialized the referred type with a call to operator=.
Because of that danger, you can optionally enable or disable some runtime checks by respectively set or clear a second Boolean template parameter.
When you compile without the NDEBUG macro, this parameter defaults to true (checks enabled). Else it defaults to false (checks disabled).
|
A flat area of memory big enough to hold an instance of deferred_type. Using this kind of trick forces us to do a lot of ugly casts (after all, data_t is just an array of char), but as a result there are no dynamic allocations. |