From 1d7712e1b785a6bece436419d71c25de1f6e25e0 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Sun, 26 Feb 2017 11:20:10 -0800 Subject: [PATCH] reconciliation between examples and documentation --- doc/boostbook/numeric_concept.xml | 6 ++++++ doc/boostbook/tutorial.xml | 6 +----- examples/example10.cpp | 2 +- examples/example4.cpp | 2 +- examples/example7.cpp | 14 +++++++------- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/boostbook/numeric_concept.xml b/doc/boostbook/numeric_concept.xml index 82c7753..42145bf 100644 --- a/doc/boostbook/numeric_concept.xml +++ b/doc/boostbook/numeric_concept.xml @@ -128,6 +128,12 @@ true or false + + std::numeric_limits<T>::is_signed + + true or false + + os << t diff --git a/doc/boostbook/tutorial.xml b/doc/boostbook/tutorial.xml index aaee84a..e704811 100644 --- a/doc/boostbook/tutorial.xml +++ b/doc/boostbook/tutorial.xml @@ -20,15 +20,11 @@ responsibility to ensure such undefined behavior is avoided. This program demonstrates this problem. The solution is to replace - instances of char type with safe<char> + instances of int type with safe<int> type. - - Note that I've used char types in this example to make - the problem and solution easier to see. The exact same example could have - been done with int types albeit with different values.
diff --git a/examples/example10.cpp b/examples/example10.cpp index ae4bf02..fc2e99b 100644 --- a/examples/example10.cpp +++ b/examples/example10.cpp @@ -17,7 +17,7 @@ void safe_f( } int main(){ - cout << "example 10: "; + cout << "example 4: "; cout << "mixing types produces surprising results" << endl; try { std::cout << "Not using safe numerics" << std::endl; diff --git a/examples/example4.cpp b/examples/example4.cpp index 845e2dd..1ff4f22 100644 --- a/examples/example4.cpp +++ b/examples/example4.cpp @@ -4,7 +4,7 @@ #include "../include/safe_integer.hpp" int main(){ - std::cout << "example 4: "; + std::cout << "example 3: "; std::cout << "implicit conversions change data values" << std::endl; std::cout << "Not using safe numerics" << std::endl; diff --git a/examples/example7.cpp b/examples/example7.cpp index de5f8ca..9ce3b0f 100644 --- a/examples/example7.cpp +++ b/examples/example7.cpp @@ -23,7 +23,7 @@ unsigned int convert( } // Use safe numeric to enforce program contract automatically -// define convient typenames for hours and minutes hh:mm +// define convenient typenames for hours and minutes hh:mm using hours_t = boost::numeric::safe_unsigned_range<0, 23>; using minutes_t = boost::numeric::safe_unsigned_range<0, 59>; @@ -36,7 +36,7 @@ auto safe_convert(const hours_t & hours, const minutes_t & minutes) { } int main(int argc, const char * argv[]){ - std::cout << "example 7: "; + std::cout << "example 8: "; std::cout << "enforce contracts with zero runtime cost" << std::endl; std::cout << "Not using safe numerics" << std::endl; @@ -52,10 +52,10 @@ int main(int argc, const char * argv[]){ std::cout << "Using safe numerics" << std::endl; try { - // parameters are guarenteed to meet requirements + // parameters are guaranteed to meet requirements hours_t hours(10); minutes_t minutes(83); // interrupt thrown here - // so the following will never throw + // so the following will never fail safe_convert(hours, minutes); } catch(std::exception e){ @@ -65,7 +65,7 @@ int main(int argc, const char * argv[]){ } try { - // parameters are guarenteed to meet requirements when + // parameters are guaranteed to meet requirements when // constructed on the stack safe_convert(hours_t(10), minutes_t(83)); } @@ -76,7 +76,7 @@ int main(int argc, const char * argv[]){ } try { - // parameters are guarenteed to meet requirements when + // parameters are guaranteed to meet requirements when // implicitly constructed to safe types to match function signature safe_convert(10, 83); } @@ -102,7 +102,7 @@ int main(int argc, const char * argv[]){ convert(hours, minutes); // zero (depending on compiler) runtime overhead // since unsafe types can be implicitly converted to corresponding - // safe types we can just pass the unsafe types. checkin will occur + // safe types we can just pass the unsafe types. checking will occur // when the safe type is constructed. safe_convert(10, 17); // runtime cost in creating parameters