I have some members that can't be initialized at construction time of the container class because the information to construct them is not available. At the moment I'm using std::unique_ptr to construct them later when the information becomes available.
The dynamic allocation/indirection is an unnecessary overhead as I know they will be constructed eventually. I could use std::optional, but I feel the semantics of std::optional will make the ones reading the code think the members are somehow optional and they might be missing which is not the case.
Is there any std library type that can hold a type for later construction with better semantics than std::optional?
EDIT: example code
struct Inner
{
Inner(int someValue)
: internalValue(someValue)
{}
int internalValue;
};
struct Outer
{
Outer(){/*...*/}
void createInner(int someValue)
{
assert(inner == nullptr);
inner = std::make_unique<Inner>(someValue);
}
// I would like to avoid the dynamic memory allocation here
std::unique_ptr<Inner> inner;
};