|
Boost : |
Subject: Re: [boost] [optional] How to define boost::none?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2014-11-19 10:58:40
2014-11-19 16:43 GMT+01:00 Peter Dimov <lists_at_[hidden]>:
> 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.
Hmm, looks like an option (although technically this is an UB)
> 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); }
And this is exactly what I try to avoid.
>
> Another is to declare none as constexpr:
>
> struct none_t {};
>
> constexpr none_t none = {};
Not an option: requires C++11
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk