Boost logo

Boost :

Subject: Re: [boost] optional<optional<T>>
From: Fernando Cacciola (fernando.cacciola_at_[hidden])
Date: 2009-09-03 00:11:57


Hi Andrei,

> Hello,
>
>
> 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 guess it depends on the context where the recursive optionals would appear.

Clearly, you can only fold while the initialization state is the same. That is,
if the outer optional<> is initialized but the inner is not, then you can't fold it.

OTOH, for a run of consistently initialized optionals, folding could make sense.
But then again it still depends on the context: if the very *structure* of the
recursion matters, the folding would be wrong.

So, I would allow optionals to recurse AND provide an explicit function/method
to "reduce" a given recursive optional as far as possible (i.e. up to the point
the initialization state changes)

HTH

--
Fernando Cacciola
SciSoft Consulting, Founder
http://www.scisoft-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk