I want to split a string by a token with std::views::split
, and for each retrieved substring invoke the std::from_chars
function.
Here is an MRE (https://godbolt.org/z/1K71qo9s4) that compiles successfully on GCC but fails to compile on MSVC:
#include <iostream>
#include <ranges>
#include <string>
#include <charconv>
int main()
{
std::string source{"10%15%20%35"};
for ( auto i : source | std::views::split('%') )
{
int x;
std::from_chars( i.begin().base(), i.end().base(), x );
std::cout << x << ' ';
}
}
What strange is that according to cppreference, the behavior of std::views::split
was changed in P2210R2, providing base()
function which effect is
Equivalent to
return cur_
Then, according to compiler support page, the P2210R2
is supported in MSVC since 19.31, so the example should work.