I have the following function
struct AlphaStore
{
unsigned int alpha1;
unsigned int alpha2;
}
struct Alpha
{
int a=1;
int b=2;
};
AlphaStore* store;
const Alpha& myFunction1(int x)
{
return reinterpret_cast<Alpha&> store->alpha1;
}
Now I would like to update the above myFunction1()
to return null or nullopt or similar thing based on value x.
For example, is it possible to write
std::optional<const Alpha&> myFunction2(int x)
{
return x? reinterpret_cast<Alpha&> store->alpha1 : nullopt;
}
If so how will I use reference on the return value?
For example, I would like to use auto* al = reinterpret_cast<const unsigned int*>(&myFunction1(arg));
How can I write this above statement if myFunction2() is used? Are there other alternative ways to return a null reference or something similar in this scenario?