Skip to content

Commit

Permalink
converted test_conversion to
Browse files Browse the repository at this point in the history
test_construction
test_assignment

pending - make m_t private
eliminate redundant bounds checking
  • Loading branch information
robertramey committed Jun 29, 2015
1 parent 97d2b6c commit d33389c
Show file tree
Hide file tree
Showing 17 changed files with 713 additions and 372 deletions.
92 changes: 0 additions & 92 deletions doc/boostbook/safe_cast.xml

This file was deleted.

106 changes: 0 additions & 106 deletions doc/boostbook/safe_compare.xml

This file was deleted.

6 changes: 0 additions & 6 deletions doc/boostbook/safe_numerics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@

<section id="safe_numerics.functions">
<title>Functions</title>

<xi:include href="safe_cast.xml" xpointer="element(/1)"
xmlns:xi="http://www.w3.org/2001/XInclude"/>

<xi:include href="safe_compare.xml" xpointer="element(/1)"
xmlns:xi="http://www.w3.org/2001/XInclude"/>
</section>

<section id="safe_numerics.exception_safety">
Expand Down
2 changes: 1 addition & 1 deletion examples/example1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, const char * argv[]){
z = x + y;
assert(false); // never arrive here
}
catch(std::range_error & e){
catch(std::exception & e){
// which can catch here
std::cout << e.what() << std::endl;
detected_msg(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int main(int argc, const char * argv[]){
++x;
assert(false); // never arrive here
}
catch(std::range_error & e){
std::cout << e.what();
catch(std::exception & e){
std::cout << e.what() << std::endl;
detected_msg(true);
}
return 0;
Expand Down
7 changes: 5 additions & 2 deletions examples/example3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ int main(int argc, const char * argv[]){
using namespace boost::numeric;
safe<int> x = -1000;
// throws exception when conversion change data value
safe<char> y = x;
safe<char> y1(x);
safe<char> y3 = x;
safe<char> y = {x};
y = x;
assert(false); // never arrive here
}
catch(std::range_error & e){
catch(std::exception & e){
std::cout << e.what() << std::endl;
detected_msg(true);
}
Expand Down
10 changes: 4 additions & 6 deletions examples/example4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>

#include "../include/safe_integer.hpp"
#include "../include/safe_compare.hpp"

void detected_msg(bool detected){
std::cout << (detected ? "error detected!" : "error NOT detected! ") << std::endl;
Expand All @@ -22,9 +21,8 @@ int main(int argc, const char * argv[]){
assert(x == -1);
// even though it's not !!!

// however, safe_compare does detect the error
assert(! boost::numeric::safe_compare::equal(x, -1));
std::cout << x << " != " << -1;
// so the error is not detected!
std::cout << x << " != " << -1 << std::endl;
detected_msg(false);
}
catch(std::exception){
Expand All @@ -39,8 +37,8 @@ int main(int argc, const char * argv[]){
--x;
assert(false); // never arrive here
}
catch(std::range_error & e){
std::cout << e.what();
catch(std::exception & e){
std::cout << e.what() << std::endl;
detected_msg(true);
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/example5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(int argc, const char * argv[]){
i_array[i_index] = 84; // so we never arrive here
assert(false);
}
catch(std::range_error & e){
catch(std::exception & e){
std::cout << e.what() << std::endl;
detected_msg(true);
}
Expand Down
Loading

0 comments on commit d33389c

Please sign in to comment.