summaryrefslogtreecommitdiff
path: root/boost/convert/strtol.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/convert/strtol.hpp')
-rw-r--r--boost/convert/strtol.hpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/boost/convert/strtol.hpp b/boost/convert/strtol.hpp
index 5d10bde5a7..de5aa29a8a 100644
--- a/boost/convert/strtol.hpp
+++ b/boost/convert/strtol.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2009-2014 Vladimir Batov.
+// Copyright (c) 2009-2016 Vladimir Batov.
// Use, modification and distribution are subject to the Boost Software License,
// Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
@@ -31,18 +31,6 @@ namespace boost { namespace cnv
struct boost::cnv::strtol : public boost::cnv::cnvbase<boost::cnv::strtol>
{
- // C2. Old C-strings have an advantage over [begin, end) ranges. They do not need the 'end' iterator!
- // Instead, they provide a sentinel (0 terminator). Consequently, C strings can be traversed
- // without the need to compare if the 'end' has been reached (i.e. "for (; it != end; ++it)").
- // Instead, the current character is checked if it's 0 (i.e. "for (; *p; ++p)") which is faster.
- //
- // So, the implementation takes advantage of the fact. Namely, we simply check if *cnv_end == 0
- // instead of traversing once with strlen() to find the end iterator and then comparing to it as in
- //
- // char const* str_end = str + strlen(str); // Unnecessary traversal!
- // ...
- // bool const good = ... && cnv_end == str_end;
-
typedef boost::cnv::strtol this_type;
typedef boost::cnv::cnvbase<this_type> base_type;
@@ -209,14 +197,20 @@ template<typename string_type, typename out_type>
void
boost::cnv::strtol::str_to_d(cnv::range<string_type> range, optional<out_type>& result_out) const
{
- typedef cnv::range<string_type> range_type;
- typedef typename range_type::value_type char_type;
-
- char_type const* str = &*range.begin(); // Currently only works with 'char'
- char* cnv_end = 0;
- ldbl_type const result = strtold(str, &cnv_end);
- bool const good = result != -HUGE_VALL && result != HUGE_VALL && *cnv_end == 0/*C2*/;
- out_type const max = (std::numeric_limits<out_type>::max)();
+ // C2. Simply check if the end-of-string was reached -- *cnv_end == 0
+ // instead of traversing once with strlen() to find the end iterator
+ // and then comparing to it as in
+ // char const* end = str + strlen(str); // Unnecessary traversal!
+ // bool const good = ... && cnv_end == end;
+
+ typedef cnv::range<string_type> range_type;
+ typedef typename range_type::value_type ch_type;
+
+ ch_type const* str = &*range.begin(); // Currently only works with 'char'
+ char* cnv_end = 0;
+ ldbl_type result = strtold(str, &cnv_end);
+ bool good = result != -HUGE_VALL && result != HUGE_VALL && *cnv_end == 0/*C2*/;
+ out_type max = (std::numeric_limits<out_type>::max)();
if (good && -max <= result && result <= max)
result_out = out_type(result);