boostorg / lexical_cast

General literal text conversions, such as an int represented as a string, or vice versa
https://boost.org/libs/lexical_cast
34 stars 58 forks source link

lexical_cast<unsigned> returns unexpected result when using with split_iterator<std::wstring::iterator> #47

Closed apolukhin closed 8 months ago

apolukhin commented 3 years ago

The following code will print "4948.4948" instead of expected "10.10" (This are ascii codes of the symbols instead of values):

std::wstring wstr(L"10.10");
typedef boost::split_iterator<std::wstring::iterator> wsplit_iter_t;
wsplit_iter_t wdot_iter = boost::make_split_iterator( wstr, boost::first_finder(L "."));
std::cout<<boost::lexical_cast<unsigned>(*wdot_iter++)<<'.'<<boost::lexical_cast<unsigned>(*wdot_iter++);

Issue on trac: https://svn.boost.org/trac10/ticket/8261

apolukhin commented 8 months ago

The examples does not compile any more on C++20 and newer:

#include <boost/algorithm/string/find_iterator.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>

int main() {
    std::wstring wstr(L"10.10");
    typedef boost::split_iterator<std::wstring::iterator> wsplit_iter_t;
    auto wdot_iter =
        boost::make_split_iterator(wstr, boost::first_finder(L"."));
    std::cout << boost::lexical_cast<unsigned>(*wdot_iter++) << '.'
              << boost::lexical_cast<unsigned>(*wdot_iter++);
}

This is dues to https://wg21.link/p1423 that deleted the problematic operators in the C++ Standard Library