Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r71901 - trunk/libs/conversion
From: antoshkka_at_[hidden]
Date: 2011-05-12 13:21:09


Author: apolukhin
Date: 2011-05-12 13:21:07 EDT (Thu, 12 May 2011)
New Revision: 71901
URL: http://svn.boost.org/trac/boost/changeset/71901

Log:
FIx #5536
Text files modified:
   trunk/libs/conversion/lexical_cast.htm | 70 ++++++++++++++++++++++++++++------------
   1 files changed, 49 insertions(+), 21 deletions(-)

Modified: trunk/libs/conversion/lexical_cast.htm
==============================================================================
--- trunk/libs/conversion/lexical_cast.htm (original)
+++ trunk/libs/conversion/lexical_cast.htm 2011-05-12 13:21:07 EDT (Thu, 12 May 2011)
@@ -196,38 +196,60 @@
                 failure.
                 
 <hr>
+<!--
+The original design of lexical_cast library does not supports throwing/nonthrowing behaviour, default values,
+locales... BOOST_LEXICAL_CAST_ASSUME_C_LOCALE is a good optimization, but it breaks down the original design.
+-->
+<!--
   <h2><a name="BOOST_LEXICAL_CAST_ASSUME_C_LOCALE"><code>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE</code></a></h2>
- <blockquote><pre>#define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
-
+ <blockquote><pre>#define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE</blockquote></pre>
 or,
-
-g++ -DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE ... (gcc on Linux/Unix)
-cl.exe /DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE ... (Visual C++ on Windows)
+ <blockquote><pre>g++ -DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE ... (gcc on Linux/Unix)</blockquote></pre>
+ <blockquote><pre>cl.exe /DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE ... (Visual C++ on Windows)</blockquote></pre>
 </pre>
 Eliminate an overhead of <code>std::locale</code> if your program runs in the "C" locale. If the option is set but a program runs in other locale, <code>lexical_cast</code> result is unspecified.
 <hr>
+-->
                 
-<h2><a name="faq">Frequently Asked Questions</h2>
- <p> Q: Why does <code>lexical_cast&lt;int8_t&gt;("127")</code> throw <code>bad_lexical_cast</code>?
- <br> A: The type <code>int8_t</code> is a typedef to <code>char</code> or <code>signed char</code>.
+<h2><a name="faq">Frequently Asked Questions</a></h2>
+
+<table>
+ <tr>
+ <td valign="top"><b>Question:</b></td>
+ <td>Why does <code>lexical_cast&lt;int8_t&gt;("127")</code> throw <code>bad_lexical_cast</code>?</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Answer:</b></td>
+ <td>The type <code>int8_t</code> is a typedef to <code>char</code> or <code>signed char</code>.
     Lexical conversion to these types is simply reading a byte from source but since the source has
     more than one byte, the exception is thrown.
- <p>Please use other integer types such as <code>int</code> or <code>short int</code>. If bounds checking
+ Please use other integer types such as <code>int</code> or <code>short int</code>. If bounds checking
     is important, you can also call numeric_cast:
-
 <pre>numeric_cast&lt;int8_t&gt;(lexical_cast&lt;int&gt;("127"));</pre>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Question:</b></td><td>What does <code>lexical_cast&lt;std::string&gt;</code> of an <code>int8_t</code> or <code>uint8_t</code> not do what I expect?</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Answer:</b></td><td>As above, note that <code>int8_t</code> and <code>uint8_t</code> are actually chars and are formatted as such. To avoid this, cast to an integer type first:
+ <pre>lexical_cast&lt;std::string&gt;(static_cast&lt;int&gt;(n));</pre>
+ </td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Question:</b></td>
+ <td>The implementation always resets the <code>ios_base::skipws</code> flag of an underlying stream object. It breaks my <code>operator&gt;&gt;</code> that works only in presence of this flag. Can you remove code that resets the flag?</td>
+ </tr>
+ <tr>
+ <td valign="top"><b>Answer:</b></td>
+ <td>May be in a future version. There is no requirement in [N1973] to reset the flag but remember that [N1973] is not yet accepted by the committee. By the way, it's a great opportunity to make your <code>operator&gt;&gt;</code> conform to the standard. Read a good C++ book, study <code>std::sentry</code> and ios_state_saver.
+ </td>
+ </tr>
+</table>
 
- <p> Q: What does <code>lexical_cast&lt;std::string&gt;</code> of an <code>int8_t</code> or <code>uint8_t</code> not do what I expect?
- <br> A: As above, note that <code>int8_t</code> and <code>uint8_t</code> are actually chars and are formatted as such. To avoid this, cast to an integer type first:
-
-<pre>lexical_cast&lt;std::string&gt;(static_cast&lt;int&gt;(n));</pre>
-
- <p> Q: The implementation always resets the <code>ios_base::skipws</code> flag of an underlying stream object. It breaks my <code>operator&gt;&gt;</code> that works only in presence of this flag. Can you remove code that resets the flag?
- <br> A: May be in a future version. There is no requirement in [N1973] to reset the flag but remember that [N1973] is not yet accepted by the committee. By the way, it's a great opportunity to make your <code>operator&gt;&gt;</code> conform to the standard. Read a good C++ book, study <code>std::sentry</code> and ios_state_saver.
-</ul>
-<h2><a name="references">References</h2>
+<h2><a name="references">References</a></h2>
 <ul type="square">
- <a name="n1973"></a><li> [N1973] Kevlin Henney, Beman Dawes, Lexical Conversion Library Proposal for TR2,
+ <li><a name="n1973"></a>[N1973] Kevlin Henney, Beman Dawes, Lexical Conversion Library Proposal for TR2,
       <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1973.html">N1973</a>.
       <a name="tuning"></a><li> [Tuning] Alexander Nasonov, Fine Tuning for lexical_cast,
       <a href="http://accu.org/index.php/journals/1375">Overload #74</a> (<a href="http://www.accu.org/var/uploads/journals/overload74.pdf">PDF</a>),
@@ -276,6 +298,12 @@
         <p>
                         <hr>
                         
-<div align="right"><small><i>&copy; Copyright Kevlin Henney, 2000&#150;2005</i></small></div>
+<div align="right"><small><i>Copyright &copy; Kevlin Henney, 2000-2005</i></small></div>
+<div align="right"><small><i>Copyright &copy; Alexander Nasonov, 2006-2010</i></small></div>
+<div align="right"><small><i>Copyright &copy; Antony Polukhin, 2011</i></small></div>
+<div align="right"><small><i>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)</i></small>
+</div>
         </body>
 </html>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk