Boost logo

Boost :

Subject: Re: [boost] [optional] How to define boost::none?
From: Peter Dimov (lists_at_[hidden])
Date: 2014-11-19 11:07:53


Andrzej Krzemienski wrote:

> > One option is to use
> >
> > struct none_rt {};
> >
> > typedef none_rt (*none_t)();
> >
> > inline none_rt none() { return none_rt(); }
>
>
> Not an option. According to GCC, the following compiles:
>
> void d(none_t) {}
> int main() { d(0); }

Right, sorry, I forgot. You can make that

    typedef none_rt (&none_t)();

and it will reject 0, but then 'none' will not pass through template
parameters.

    void d( none_t ) {}
    template< class T > void e( T t ) { d( t ); }
    int main() { e( none ); }

Not sure if you need that, but you probably do.


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