Boost logo

Boost :

Subject: [boost] [optional] using name boost::in_place -- need your opinion/advice
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2016-05-30 03:47:14


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

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 wonder if anyone here needed to face a similar problem, and if you can
think of an elegant solution.

Thanks,
&rzej


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