|
Boost : |
Subject: Re: [boost] [optional] using name boost::in_place -- need your opinion/advice
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2016-05-30 06:30:08
2016-05-30 11:29 GMT+02:00 Andrey Semashev <andrey.semashev_at_[hidden]>:
> On Monday, 30 May 2016 12:13:04 MSK Andrzej Krzemienski wrote:
> > Hi Everyone,
> > I have stumbled upon a problem that I do not know how to address. I would
> > like to seek an advice from the people in this list.
> >
> > I am trying to make boost::optional resemble std::optional (where it is
> > reasonably easy to achieve). std::optional has this nice and useful
> > "placement" constructor:
> >
> > std::optional<std::mutex> m {std::in_place};
> >
> > std::in_place is a tag type, that instructs std::optional to create an
> > object using placement-new syntax, from the provided arguments (zero in
> the
> > example), without incurring any move construction.
> >
> > I cannot easily copy 1-to-1 this solution, because in namespace boost
> name
> > in_place is reserved for the in-place factories:
> >
> http://www.boost.org/doc/libs/1_61_0/libs/utility/in_place_factories.html
>
> If not the typed in-place factories, you could transform in_place to be a
> namespace
> scope function object and use it as a tag in the optional constructor.
+1
> The typed in-place
> factories ruin the solution though, even if not used by optional.
>
How so?
>
> > I could simply go with a different name for a tag, but something tells me
> > it would introduce an unnecessary complications for users that want to
> > migrate from one optional to another. I could hack in-place factories so
> > that they can also be used as a tag, although, I am not sure it is doable
> > in a type-safe manner, and if it would not confuse people to have this
> > boost::in_place do a number of different things.
> >
> > I could use a different namespace, but again, this might look
> surprising.I
> > am a bit torn.
>
> I think that would be the best solution. Additionally, I would suggest
> moving the whole
> library to its own namespace (e.g. optionals). Then the tag in the library
> namespace
> would look more natural. For backward compatibility you could import the
> optional class
> template into boost namespace.
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk