boost::adaptors::indirected
References
Headers
boost::adaptors::indirected
is available by including
any of the following headers:
boost/range/adaptor/indirected.hpp
orboost/range/adaptors.hpp
Examples
indirected-pipe.cpp
#include <iostream>
#include <vector>
#include <boost/range/adaptors.hpp>
const std::vector<int> vec = { 0, 1, 2 };
const std::vector<const int*> ptr_vec = { &vec[0], &vec[1], &vec[2] };
int main() {
// indirected() is a good solution for iterating over a container of pointers
// or iterators. It avoids the (*it)->... ideom.
std::cout << "Easy iteration over a vector of pointers" << std::endl;
for (int i : ptr_vec | boost::adaptors::indirected) {
std::cout << i << " ";
}
std::cout << std::endl;
return 0;
}
Output:
Easy iteration over a vector of pointers
0 1 2
Boost Range for Humans
This reference is part of Boost Range for Humans. Click the link to the overview.