mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-22 03:32:24 +00:00
Resolving issues related to error policy - first cut. Passes all tests except shift / undefined behavior.
Still needs to be redone - but on the right track.
This commit is contained in:
@@ -11,12 +11,12 @@ using namespace boost::numeric; // for safe_literal
|
||||
// create a type for holding small integers. We "know" that C++
|
||||
// type promotion rules will work such that addition will never
|
||||
// overflow. If we change the program to break this, the usage
|
||||
// of the trap_exception promotion policy will prevent compilation.
|
||||
// of the no_exceptions_policy will prevent compilation.
|
||||
using safe_t = safe_signed_range<
|
||||
-24,
|
||||
82,
|
||||
native, // C++ type promotion rules work OK for this example
|
||||
trap_exception // catch problems at compile time
|
||||
no_exceptions_policy // catch problems at compile time
|
||||
>;
|
||||
|
||||
int main(int argc, const char * argv[]){
|
||||
@@ -25,8 +25,8 @@ int main(int argc, const char * argv[]){
|
||||
// since the sum of x and y wouldn't be in the legal
|
||||
// range for z.
|
||||
// const safe_signed_literal<20> x;
|
||||
const safe_signed_literal<10, native, trap_exception> x; // no problem
|
||||
const safe_signed_literal<67, native, trap_exception> y;
|
||||
const safe_signed_literal<10, native, no_exceptions_policy> x; // no problem
|
||||
const safe_signed_literal<67, native, no_exceptions_policy> y;
|
||||
|
||||
const safe_t z = x + y;
|
||||
std::cout << "x = " << safe_format(x) << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user