feature request for optional

Hi there, 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. Greetings, Sascha

Hi Sascha,
[...] But when i store values where the type has an inline NaT value (for example NULL pointers) i cannot and need not use optional.
Can you explain why you cannot use optional<>? I definitely see that you don't need it, but for the sake of genericity I just wouldn't mind the fact that some types do have an identifiable null value and use optional<> all along. Fernando Cacciola SciSoft http://fcacciola.50webs.com/
participants (3)
-
Fernando Cacciola
-
Gennaro Prota
-
Sascha Krissler