![]() |
Safe Numerics |
This type contains the functions to return a type with sufficient capacity to hold the result of a given arithmetic operation.
The following example illustrates the automatic type
being passed as a template parameter for the type
safe<int>.
#include <boost/safe_numerics/safe_integer.hpp> #include <boost/safe_numerics/automatic.hpp> int main(){ using namespace boost::numeric; // use automatic promotion policy where C++ standard arithmetic might lead to incorrect results using safe_t = safe<std::int8_t, automatic>; // In such cases, there is no runtime overhead from using safe types. safe_t x = 127; safe_t y = 2; auto z = x + y; // z is guarenteed correct without any runtime overhead or interrupt. return 0; }