Slicing a vector

后端 未结 8 1969
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 01:12

I have a std::vector. I want to create iterators representing a slice of that vector. How do I do it? In pseudo C++:

class InterestingType;

void doSomethi         


        
8条回答
  •  攒了一身酷
    2020-12-14 01:58

    use boost range adapters. they are lazy:

    operator|() is used to add new behaviour lazily and never modifies its left argument.

    boost::for_each(v|sliced(1,5)|transformed(doSomething));
    

    doSomething needs to take range as input. a simple (may be lambda) wrapper would fix that.

提交回复
热议问题