Beta

Transform view

Description
Loading description...
Iterators
Algorithms
  • Please sign in or sign up to leave a comment.
  • FArekkusu Avatar

    The transform and filter katas are really nice, figuring out all the stuff required to implement a proper generic C++ iterator and please the type system was really interesting and challenging. But at the same time it's really bad that you authored 2 separate katas on the same topic. The solution to both of them is almost identical, the changes required to convert map to filter (or vice-versa) are trivial, and as soon as one kata gets approved, the other will instantly turn into a duplicate. You should either rework them into one asking to implement both map and filter, or simply unpublish one of the katas, as they will not survive together.

    • FArekkusu Avatar

      @sv90 are you going to address this issue somehow? If not, I think I'll open an issue on CW github, so that the community can decide what do with these 2 katas (unless somebody comes up with a reason why none of them should be approved at all - in fact, these katas might become obsolete with the introduction of C++20 support on CW in the future, so this case is quite possible too).

  • lolisa Avatar

    f might apply to a element multiple amount of time. Should test for single application of f as well.

    • sv90 Avatar

      I don't understand what you mean. Could you please provide an example of what you mean?

    • lolisa Avatar

      suppose we have a iterator iter of a transformed view dereferencing iter will call function F once dereferencing again will call function F another time but if it can be cached so function F is only called once until you increment iter.

    • sv90 Avatar

      I wasn't sure weather that would impose too much overhead. So I tested the following code using the reference implementation of the Ranges-TS

      #include <range/v3/all.hpp>
      #include <vector>
      #include <iostream>
      
      int main() {
        std::vector<int> vec{1, 2, 3};
        unsigned n = 0;
        auto transformed = ranges::view::transform(vec, [&n](auto x) {
            ++n;
            return 2 * x;
          });
        (void)*transformed.begin();
        (void)*transformed.begin();
        std::cout << n << '\n';
      }
      

      It prints 2 so there is no caching here. I would like to keep this kata close to the proposal so I wont force the solutions to be cached. I hope you agree.

      Issue marked resolved by sv90 8 years ago
    • lolisa Avatar

      This reason make sense to me.