Reputation: 1057
C++ boost::optional question. How can I cast boost::optional myInt to an int (safely). In my program I have an if statement that checks myInt is indeed initialized, so I want to pass it around in different functions as an int rather then boost::optional for readability purposes. Thanks in advance!
Upvotes: 1
Views: 2258
Reputation: 44274
Can't you just do
boost::optional<int> x;
//....
//....
if (x)
{
int y = *x; // or y = x.get();
}
Upvotes: 4