boost::adaptors::transformed
References
Headers
boost::adaptors::transformed
is available by including
any of the following headers:
boost/range/adaptor/transformed.hpp
orboost/range/adaptors.hpp
orboost/range/adaptor/map.hpp
Examples
transformed-pipe.cpp
#include <iostream>
#include <vector>
#include <boost/range/adaptors.hpp>
const std::vector<int> vec = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
/** Map integers to the alphabet: 0->a, 1->b, ... */
std::string alphabetize(int i) {
return std::string(1, 'a' + i);
}
int main() {
// transformed() is a nice and general way to change elements in a Boost
// Range. Even type conversions work fluently, as shown here:
std::cout << "Transform a vector<int> into letters: "
<< (vec | boost::adaptors::transformed(alphabetize))
<< std::endl;
return 0;
}
Output:
Transform a vector<int> into letters: abcdefghij
Boost Range for Humans
This reference is part of Boost Range for Humans. Click the link to the overview.