I don't understand why there is no optional tuple
, and I mean by that, something like this ; optional<int,string,char>
that would combine an optional int
, optional string
and optional char
.
You can think of it like an optimized std::tuple<boost::optional<T>...>
where the booleans
used by the optionals
would be all together at the end of the structure
in order to pack it, or even better, be stored in a bitset.
That may reduce the memory of the structure A LOT, and also is more elegant :
std::tuple<boost::optional<int>,boost::optional<string>,boost::optional<char>>
VS
optional<int,string,char>
I can think of a way of doing this, using the implementaion of boost::optional
and variadic templates
, but before starting this, I would like to know if this is a good idea, what would be a better way of implementing this, what are the difficulties I would be facing ?
EDIT :
Basically why I don't like std::tuple<boost::optional<T>...>;
Since an optional<T>
is a union of T
and a bool
:
The new structure can save a lot of memory !!
You may implement yourself, something similar to:
Live Demo