Re: [Boost-bugs] [Boost C++ Libraries] #8261: lexical_cast<unsigned> returns unexpected result when using with split_iterator<std::wstring::iterator>

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8261: lexical_cast<unsigned> returns unexpected result when using with split_iterator<std::wstring::iterator>
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-02-01 16:48:26


#8261: lexical_cast<unsigned> returns unexpected result when using with
split_iterator<std::wstring::iterator>
-------------------------------+--------------------------
  Reporter: s.a.moreno.a.s@… | Owner: apolukhin
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: lexical_cast
   Version: Boost 1.52.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+--------------------------

Comment (by apolukhin):

 Replying to [comment:2 Troy Korjuslommi <troykor@…>]:
> The attached patch is against boost 1.55.0's lexical_cast.hpp.
>
> This patch catches iterator_range objects and calls a version of
 lexical_cast specialized on the correct internal char type.
>
> The root cause is that the templates in the default lexical_cast
 function do not consider iterator_range objects. It is more efficient to
 catch all iterator_range objects in a specialized function.

 This is a good attempt, however it will break one of the usecaes:
 &lexical_cast<int, char*>. This situation is covered by the regression
 test, which could be run by ./b2 in boost/libs/conversion/tests/ folder.
 Breaking existing use cases is unfordable.

> Another issue which might be of concern is that the member variables
 start and finish (start_ and finish_ would be a nice change) are pointers
 to char types. Using an iterator abstraction would be more generic. It
 looks like a big change at first peak, and its merits would have to
 evaluated too.

 This will increase the size of a resulting binary without actually adding
 new functionality.
 [[BR]]
 [[BR]]

 The issue in this ticket comes from the ability of
 `iterator_range<std::wstring::iterator>` to stream using `std::stream` and
 `std::wstream`. `lexical_cast` chooses the `std::stream` version,
 according to the assumption that non wide character streaming is more
 optimized and used more often by users, leading to smaller binary size.

 Same issue occurs with any wide&non-wide streamable classes.


 A simple solution would be to specialize `detail::stream_char_common` (can
 be found in boost/lexical_cast.hpp) for
 `std::wstring::iterator/std::string::iterator/std::6string::const_iterator/std::wstring::const_iterator`
 and ensure that `lexical_cast` works well with `std::wstring::iterator`
 and `iterator_range<std::wstring::const_iterator>`.

 A super cool solution would be to additionally resolve some of the cases
 with wide&non-wide streamable classes by introducing a
 `boost::has_right_shift<std::basic_istream<char>, T >` type trait that
 does not allow implicit conversions and type promotions for `T`. Not know
 how to do it thou.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8261#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC