Boost logo

Boost :

From: Mat Marcus (mmarcus-boost_at_[hidden])
Date: 2003-09-17 16:02:05


[snip]

Mat wrote:
>> I imagine that it could be useful to have something like a
>> universal 'none' object that could be passed to functions
>> expecting optionals. I would expect its effect to be the same as
>> passing the anonymously constructed optional in the line of code
>> directly above. That is I would like to write:
>>
>> out_edge_iterator end(none); file://optional::none?
>>

[snip]

Fernando wrote:

> There are just a few small issues worth discussing:
>
> (1) name: how about 'nothing', as in Haskell's Maybe "Nothing" (I
> prefer 'none' though) (2) namespace: 'boost::_unnamed_ns_'?
> (3) header: utility/none.hpp?
> (4) interoperability: given that 'none' will be used by optional<>
> but won't be totally tied to it, are there other uses for such a
> thing that should be considered?

Hmm. What to name a universal nothing singleton. And what should its
type be? Reminds me of a very long NULL discussion we've been having
on the committee reflectors, but lets not go there. I can think of
some other uses too. A couple of thoughts:

  * 'None' holds appeal because it is short
  * 'Nothing' might work where ignore does today (with tie)
  * 'Default' might be a nice if the general idiom one wanted to
support was shorter 'naming' of default constructed anonymous objects.
That is, any class could offer an implicit constructor from 'default'.

For fun you could try instead something like:

class Default { // not sure of the name of this type, or its instance
public:
    template <class T>
    operator T() {return T();}
private:
    Default();
};

extern Default default;

Then given a class Bar with a default constructor it becomes rather
concise to supply an anonymously constructed Bar():

   foo(default);

Of course there are limitations with regard to disallowed double
conversions and issues with function templates to be sure. But it
still seems somewhat amusing.

 - Mat


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