Subject: Re: [boost] optional<optional<T>>
From: Christopher Jefferson (chris_at_[hidden])
Date: 2009-09-03 11:21:08
On 3 Sep 2009, at 03:43, Andrei Alexandrescu wrote:
> I'm defining an "optional" type for D's standard library modeled
> similarly to Boost.optional. An interesting question came up -
> should optional<optional<T>> fold itself into optional<T>, or is
> "double optional" an interesting concept of its own?
> I thought I'd ask here because by now there's a significant body of
> experience with optional<T>. I perused the online documentation and
> the forum and couldn't find information about that specific detail.
Only a related note, I use a version of optional which takes the
"m_initalized", effectively the boolean that tells you if a value is
present, as a template parameter.
This is because for many types, it is possible to know there is some
value in the object itself which cannot take certain values, so can be
As an example, given a vector<T> implemented as:
Then I know that (on my system) begin will never take (void*)(1), (it
might be NULL), so I can reuse that to implement optional<T> without
any extra space usage.
The main problem with this, at least in C++, this is basically
impossible to implement generically and legally, as you are
effectively poking into an objects memory without knowing what it is,
so I haven't tried to carefully formalise it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk