Loki::CheckReturn< Value, OnError > Class Template Reference
#include <CheckReturn.h>
List of all members.
Detailed Description
template<class Value, template< class > class OnError = TriggerAssert>
class Loki::CheckReturn< Value, OnError >
- Purpose
- C++ provides no mechanism within the language itself to force code to check the return value from a function call. This simple class provides a mechanism by which programmers can force calling functions to check the return value. Or at least make them consciously choose to disregard the return value. If the calling function fails to use or store the return value, the destructor calls the OnError policy.
- Template Parameters
- CheckReturn has two template parameters, Value and OnError.
- Value is the return type from the function. CheckReturn stores a copy of it rather than a reference or pointer since return value could be local to a function. CheckReturn works best when the return type is a built-in primitive (bool, int, etc...) a pointer, or an enum (such as an error condition enum). It can work with other types that have cheap copy operations.
- OnError is a policy class indicating how to handle the situation when a caller does not check or copy the returned value. Loki provides some policy classs and you may also write your own. For example, you can write a policy to create a message box when the function ignores the return value. That would quickly tell you places where code ignores the function call. If your write your own, you only need a templated class or struct with a public function named "run" that accepts a reference to a const value.
- Provided Policy Classes
- IgnoreReturnValue Deliberately ignores when the caller ignores the return value.
- TriggerAssert Asserts in debug builds if the caller ignores the return value.
- FprintfStderr Prints out an error message if the caller ignores the return value.
- ThrowTheValue Throws the ignored value as an exception.
- ThrowLogicError Throws a logic_error exception to indicate a programming error.
Constructor & Destructor Documentation
template<class Value , template< class > class OnError = TriggerAssert>
Copy-constructor allows functions to call another function within the return statement. The other CheckReturn's m_checked flag is set since its duty has been passed to the m_checked flag in this one.
References Loki::CheckReturn< Value, OnError >::m_checked.
The documentation for this class was generated from the following file: