
A typical approach is to consider the existence of a valid return value as a postcondition, so that if the function cannot compute the value to return, it has either undefined behavior (and can use assert in a debug build) or uses a runtime check and throws an exception if the postcondition is violated. This is a reasonable choice for example, for function (A),
This is possibly technically correct, but confusing. Undefined behavior results from precondition violations, not postcondition violations. I'd suggest: One approach is to make a non-negative argument a precondition, so when violated the function has undefined behavior (and can use assert in a debug build). Alternatively, one can use a runtime check and specify that an exception is thrown if the postcondition cannot be satisfied. These are a reasonable choice for example, for function (A), I'm not sure the first sentence is quite right for your needs, but I'm out of time to improve it further. -- Dave Abrahams BoostPro Computing Software Development Training http://www.boostpro.com Clang/LLVM/EDG Compilers C++ Boost