I have a couple of variants whose inner type are all references. For example,
variant var1;
variant var2;
Because this variant will not be assignable due to the references,
they need to be initialized in a constructor initializer list.
However, it's possible for the function that creates these references
in the first place to throw, and moreover the inner types might
contain unmanaged resources that need to be properly cleaned up on a
throw. Also the construction of var_k, might depend upon the
successful construction of var_j where j v1_type;
typedef variant v2_type;
struct package
{
package(v1_type& v1, v2_type& v2)
: var1_(v1), var2_(v2)
{
}
v1_type var1_;
v2_type var2_;
};
and then only have one instance of package in my class. Then, in the
initializer list call package_(create_package()), and define
create_package() as:
package create_package()
{
optional v1;
optional v2;
try
{
v1 = create_v1();
v2 = create_v2();
return package(v1.get(), v2.get());
}
catch(...)
{
}
}
but for some reason this fails to compile, saying that it's trying to
call variant::operator= in the package constructor. Which doesn't
make sense since I don't think it should be.