#include <preconditions.h>
List of all members.
Static Public Member Functions |
static void | check (bool expression) |
static void | check (bool expression, const char *message) |
template<typename T > |
static void | checkRange (T index, T size) |
template<typename T > |
static void | checkRange (T index, T low, T high) |
template<typename T > |
static void | checkNotNull (const T *ptr) |
Detailed Description
Preconditions is a helper class containing static methods that can check the validity of function arguments (function pre-conditions). In case there is a failure, Preconditions will throw an std::invalid_argument error.
Note: Do not overuse the throwing/catching exceptions. Failed preconditions are running much slower because of branch prediction and slowness of exceptions.
Member Function Documentation
static void Preconditions::check |
( |
bool |
expression | ) |
[inline, static] |
Checks whether the expression is true
- Parameters:
-
expression | value that is expected to be true |
- Exceptions:
-
invalid_argument | if expression is false |
static void Preconditions::check |
( |
bool |
expression, |
|
|
const char * |
message |
|
) |
| [inline, static] |
Checks whether the expression is true
- Parameters:
-
expression | value that is expected to be true |
message | of the thrown expection if case of failure |
- Exceptions:
-
invalid_argument | if expression is false |
template<typename T >
static void Preconditions::checkNotNull |
( |
const T * |
ptr | ) |
[inline, static] |
Checks that pointer is not NULL.
- Exceptions:
-
invalid_argument | in case of an error |
template<typename T >
static void Preconditions::checkRange |
( |
T |
index, |
|
|
T |
size |
|
) |
| [inline, static] |
Check that index is in range [0, size)
Warning: never ever override this template for using two different types - it may end up with nasty results because of casting like checkRange(unsigned int, int) and check will be done in ints!
- Exceptions:
-
invalid_argument | in case of an error |
template<typename T >
static void Preconditions::checkRange |
( |
T |
index, |
|
|
T |
low, |
|
|
T |
high |
|
) |
| [inline, static] |
Check that index is in range [low, high)
- See also:
- warnings for checkRange(index, size) implementation
- Exceptions:
-
invalid_argument | in case of an error |
The documentation for this class was generated from the following file: