From: anshu khare (anshukhare1998_at_[hidden])
Date: 2020-01-22 13:16:18


Hi mentors

I was going through the optional library of boost.
I was facing some problem in understanding the code base.

In lines from 94 to 97 in optional.hpp, the code is as follows:

struct in_place_init_if_t
{
Struct init_tag{};
explicit in_place_init_if_t(init_tag) {} //not able to understand this line

};

I understand that we are creating a structure in_place_init_if_t and inside
that we are creating another structure init_tag and then we are calling the
constructor of in_place_init_if_t.

But I am not able to understand that what does it the constructor do when
we pass init_tag as an argument to it.

Is it same as we are creating a structure Car and then creating another
structure wheels inside it and passing wheels as an argument to the
constructor of car as follows:

struct car
{
Struct wheels{};
explicit car(wheels) {} //not able to understand this line

};

Could you please tell what is the significance of passing wheels as an
argument in this counter example?