I'm using a function that returns an std::pair
:
std::pair<bool, int> myFunction() {
//Do something...
if (success) {
return {true, someValue};
}
else {
return {false, someOtherValue};
}
}
On success, the pair's first value will be true
, otherwise false
.
Some functions that call myFunction()
use the returned pair's second value, others don't. For those, I'm calling myFunction()
like this:
bool myOtherFunction() {
//Do something...
bool success;
std::tie(success, std::ignore) = myFunction(); //I don't care about the pair's second value
return success;
}
Is there a way to avoid declaring bool success
and returning myFunction()
's return value's first element directly?