Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
|
Go to the source code of this file.
Functions | |
template<typename SuppliedType , typename RequiredType > | |
void | STATIC_ASSERT_CHECK_INTEGER_OVERFLOW () |
void STATIC_ASSERT_CHECK_INTEGER_OVERFLOW | ( | ) | [inline] |
This template is used to ensure (at compile type) that user can't pass integral value of bigger type than specified. This is very useful to remind users about possible overflows. Note that this template is also checking unsigned->signed
Note: this template is quite aggresive, you may want to consider using run-time checks (especially signed constants versus unsigned expected)
Basic usage is:
template <typename t>=""> userFunction(T arg1) { STATIC_ASSERT_CHECK_INTEGER_OVERFLOW<T, short>(); short tmp = (short) arg1; }
and this code won't compile for example for T=32bit int (and short = 16bit int)