I'm trying to add a new constructor an existing class and wondering if I can somehow do an emplace
initialization of an optional
and then use that value in the initializer for another member value.
For example:
class sample {
my_type sc;
optional<opt_type> run;
sample() :
sc( gen_default() ) {
}
enum ctor_alt { ctor_alt };
sample( ctor_alt ) :
emplace( run, ctor_arg ), /* Possible somehow? */
sc( run.field ) {
}
My primary motivation is that I don't want to alter the type of my_type
. There are many users of this variable and putting it in a wrapper would require changing a lot of code.