ericniebler / range-v3

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

views::intersperse change element property? #1726

Closed dangdkhanh closed 1 year ago

dangdkhanh commented 1 year ago

Is this unusual behavior? I use code like this:

const std::vector<myclass > v((*array).begin(), (*array).end());
myclass var;
const std::vector<myclass >& rng = v | ranges::views::intersperse(var)
| ranges::to<std::vector<myclass >>();

However after run, properties of var in rng have been changed.

Thanks you.

brevzin commented 1 year ago

Please provide a minimal, reproducible example.

dangdkhanh commented 1 year ago

Hi brevzin, This class type is in the 3rd library,myclass similar variant type(i.e. can be int, double , string or an array) defined by property 'class_type'

In my code the values of myclass are string, andalso var is string;

Example : vector v("a","b","c") and var("-")
desired result: vector rng("a","-","b","-","c") but intersperse return 
rng("a",{"-"},"b",{"-"},"c")

I mean intersperse values going from string to array string.

Currently I need to use transform to get this first element.

brevzin commented 1 year ago

Sorry, I really don't understand what that means - or what's the difference between the desired result and what's being returned, or what the problem is. Without a clear, reproducible example of the issue - a complete program which produces one result, where you expect a different result - I can't help you.

dangdkhanh commented 1 year ago

Hi brevzin, Thanks you. from this code i found out the cause came from the library i was using.

line81: constexpr explicit cursor_adaptor(range_value_t<Rng> const & val)
              : val_{val}

problem has been solved.