Suppose a vector with values [0,1,2,3,4,5,6,7,8,9]. How can I create a vector that refers to not necessarily contiguous values, e.g. [3,4,7,9], i.e. given by some index, by using STL.
Suppose a vector with values [0,1,2,3,4,5,6,7,8,9]. How can I create a vector that refers
Share
You can express this as a transformation, e.g.:
I used a lambda, but you can also use
std::bindor the (now deprecated)std::bind2ndfor this.The example with C++11’s
std::bindmakespick:It’s seriously ugly though because of the need to cast the member function pointer to resolve the overload of
at(const vs non-const versions).