Generating functors with iterator behavior

前端 未结 4 1728
温柔的废话
温柔的废话 2021-02-04 13:53

I have a question, which very likely has been asked like this before, because I think what I want is something that a considerable amount of people would want. However I could n

4条回答
  •  梦毁少年i
    2021-02-04 14:21

    The C++ library already offers some algorithms that implement most of the functionality you're trying to do on your own. I think it's better for you to adapt your template so that it would work seamlessly with the C++ library, instead.

    I'm thinking specifically of std::generate().

    So, you take what you're planning to do in your step #1, but replace step #2 with implementing an operator() that returns the next value in the sequence.

    Then, you can let std::generate() take care of populating an actual sequence with your values.

提交回复
热议问题