Given that all else is equal, and there are no coding standards defining the best approach, what would be the recommended way in C++ to check that a value exists and return it if it does?
For example, something like one of these declarations:
bool getMethod(double& ret); double getMethod(bool& ok); void getMethod(bool& ok, double& ret); pair<bool, double> getMethod(); bool checkMethod(); // eg if (checkMethod()) double getMethod(); // result = getMethod();
or something else, like return a struct
The value may exist about 50% of the time.
The existing code already does a lot of the last method, i.e. using a checkMethod() but I was wondering if that's really an efficient way to do it - via two calls (half the time).