boost::adaptors::indirect

References

Headers

boost::adaptors::indirect is available by including any of the following headers:

  • boost/range/adaptor/indirected.hpp or
  • boost/range/adaptors.hpp

Examples

indirected-function.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() {
    // indirect() 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 : boost::adaptors::indirect(ptr_vec)) {
        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.