6 Sep 17:13
[lexical_cast] bad_lexical_cast behavior?
From: Hrvoje Prgeša <hrvoje.prgesa <at> gmail.com>
Subject: [lexical_cast] bad_lexical_cast behavior?
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-09-06 15:16:40 GMT
Subject: [lexical_cast] bad_lexical_cast behavior?
Newsgroups: gmane.comp.lib.boost.user
Date: 2008-09-06 15:16:40 GMT
From the documentation: "If the conversion is unsuccessful, a bad_lexical_cast exception is thrown. " "Exception used to indicate runtime lexical_cast failure. " So the question is when will the conversion fail? Unit tests check for the cases between [min(), max()], but what about under/overflows (>max, <min)? Is it unspecified? It seems it is currently handled a bit inconsistent: #include <boost/test/unit_test.hpp> #include <boost/lexical_cast.hpp> #include <limits.h> using std::string; using std::numeric_limits; using boost::lexical_cast; string s; // warning: needs to be a part of a unit test //#define min max #define T short // add a digit! s = lexical_cast<string, T>(numeric_limits<T>::min()) + "0"; BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // throws s = lexical_cast<string, T>(numeric_limits<T>::min()) + "5"; BOOST_CHECK_THROW(lexical_cast<T>(s), boost::exception); // throws(Continue reading)
RSS Feed