h-2 / blog-comments

comment repository for my blog
1 stars 0 forks source link

Tutorial: Writing your first view from scratch (C++20 / P0789) #4

Open h-2 opened 6 years ago

Flaneur3434 commented 1 year ago

The custom view in the article doesn't work when called next to each other.

    std::vector<int> vec{1, 5, 6, 8, 5};
    auto v = vec 
             | ranges::views::transform([] (int const i) { return i*i; }) 
             | view::add_constant
             | view::add_constant
             | ranges::views::drop(2);
    std::cout << *std::begin(v) << '\n'; // prints '136' instead of '236'

I tried to reason through the code and try to debug it, but I'm a novice. Could you try fixing it and provide an explanation?