From b1c1eb8095834bcf32810388b7900933e79f2bad Mon Sep 17 00:00:00 2001
From: Akim Demaille <akim@lrde.epita.fr>
Date: Wed, 27 Mar 2013 16:49:11 +0100
Subject: [PATCH] doc: other fixes in the example
* doc/numeric_cast.qbk: Shorten wording.
Add missing end-of-line in output.
'f' must be available, don't leave it in too short a scope.
---
doc/numeric_cast.qbk | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/doc/numeric_cast.qbk b/doc/numeric_cast.qbk
index a6a7ec5..7940573 100644
a
|
b
|
The following example performs some typical conversions between numeric types:
|
111 | 111 | short s=numeric_cast<short>(i); // This conversion succeeds (is in range) |
112 | 112 | } |
113 | 113 | catch(negative_overflow& e) { |
114 | | std::cout << e.what(); |
| 114 | std::cout << e.what() << std::endl; |
115 | 115 | } |
116 | 116 | catch(positive_overflow& e) { |
117 | | std::cout << e.what(); |
| 117 | std::cout << e.what() << std::endl; |
118 | 118 | } |
119 | 119 | |
| 120 | float f=-42.1234; |
120 | 121 | try |
121 | 122 | { |
122 | | float f=-42.1234; |
123 | | |
124 | | // This will cause a boost::numeric::negative_overflow exception to be thrown |
| 123 | // This will throw a boost::numeric::negative_overflow exception. |
125 | 124 | unsigned int i=numeric_cast<unsigned int>(f); |
126 | 125 | } |
127 | 126 | catch(bad_numeric_cast& e) { |
128 | | std::cout << e.what(); |
| 127 | std::cout << e.what() << std::endl; |
129 | 128 | } |
130 | 129 | |
131 | 130 | double d= f + numeric_cast<double>(123); // int -> double |
… |
… |
The following example performs some typical conversions between numeric types:
|
134 | 133 | |
135 | 134 | try |
136 | 135 | { |
137 | | // This will cause a boost::numeric::positive_overflow exception to be thrown |
| 136 | // This will throw a boost::numeric::positive_overflow exception. |
138 | 137 | // NOTE: *operations* on unsigned integral types cannot cause overflow |
139 | 138 | // but *conversions* to a signed type ARE range checked by numeric_cast. |
140 | 139 | |
141 | 140 | unsigned char c=numeric_cast<unsigned char>(l); |
142 | 141 | } |
143 | 142 | catch(positive_overflow& e) { |
144 | | std::cout << e.what(); |
| 143 | std::cout << e.what() << std::endl; |
145 | 144 | } |
146 | 145 | |
147 | 146 | |