Boost logo

Boost :

Subject: Re: [boost] [optional] using name boost::in_place -- need your opinion/advice
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-05-30 06:50:01

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:
> >
> 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. The
> typed in-place
> factories ruin the solution though, even if not used by optional.
> > 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.

Hmm. Moving optional to a nested namespace has other benefits also:
disabling unintended ADL. But I can't see how I can be made to work for a
tag like in_place.

If I put it also into a nested namespace and then do a:

  namespace boost{
    using nested::in_place

It will still collide with the current in-place factories. Or did I
misunderstand your suggestion?


Boost list run by bdawes at, gregod at, cpdaniel at, john at