From: Sascha Krissler (boost-dev_at_[hidden])
Date: 2006-08-04 20:36:02
while working on a hash map implementation i needed a way to
represent NaT (Not A Thing) in the underlying container (a vector)
Besides an out of line boost :) dynamic_bitset i use optional
for that purpose. But when i store values where the type has an
inline NaT value (for example NULL pointers) i cannot and need not
use optional. This complicates my code as i have to provide a special
case implementation for inline NaTs. Furthermore when the inline NaT
value is not 0, i have to specialize the check for the validity of the
value (! variable vs. variable == null_value). It would simplify my
code and be a consistent addition to add inline NaT to optional.
A suggestion would be optional<T, bool Inline> and an empty base
class that optionally has a static member for the null value
(when Inline == true).
The problem with that is that there can be only one null value for
each data type, so it might be better to make it optional<T, int Optional>
where Optional != 0 means inline NaT.
Then the problem is to keep track of the different discriminators
throughout the code (another reason why templates should not be
completely functional without state and side effects).
But maybe you find a solution if you think the addition is worth it.
I searched the archives, if this was topic before i apologize.