Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
src/utils/assert/integer_overflow.h File Reference
#include "utils/static_assert/static_assert.h"
#include <limits>
Include dependency graph for integer_overflow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename SuppliedType , typename RequiredType >
void STATIC_ASSERT_CHECK_INTEGER_OVERFLOW ()

Function Documentation

template<typename SuppliedType , typename RequiredType >
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)

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines