ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 440 forks source link

Split words in VS2019 #1627

Open ethiy opened 3 years ago

ethiy commented 3 years ago

The following code is for splitting a string into a vector of strings. It works well with gcc and clang but fails when compiled with VS 2019.

#include <string>

#include <range/v3/view/split.hpp>
#include <range/v3/view/transform.hpp>

std::string value{""line 58 56""};

auto words = value | ranges::views::split(separator) | ranges::views::transform(
    [](auto && word)
        {
            return word | ranges::to<std::string>();
        }
) | ranges::to_vector;

Expected output: std::vector<std::string>{"line", "58", "56"} Result with VS 2019: std::vector<std::string>{ "l", "i", "n", "e", " ", "5", "8", " ", "5", "6" }

Aster89 commented 1 year ago

I wonder how much this is related to this.

ethiy commented 1 year ago

I wonder how much this is related to this.

I am not sure but I do not think so. Either way, this library is supposed to be superseded by the standard library in C++20.

Aster89 commented 1 year ago

this library is supposed to be superseded by the standard library in C++20.

C++20 is already out there, and it didn't supersede Range-v3: image