Boost logo

Boost :

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


Andrzej Krzemienski wrote:
> 2014-11-19 16:28 GMT+01:00 Krzysztof Czainski <1czajnik_at_[hidden]>:
> > And then, why wouldn't a straightforward solution work:
> >
> > struct none_t {};
> >
> > none_t const none = {}
>
> I think it validates ODR, or doesn't it?

It does violate ODR at places (without any ill effects AFAIK). Bind's
placeholders have the same problem. One option is to use

    struct none_rt {};

    typedef none_rt (*none_t)();

    inline none_rt none() { return none_rt(); }

Another is to declare none as constexpr:

    struct none_t {};

    constexpr none_t none = {};


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