Branch | Status |
---|---|
Master |
A single header iterator that allows you to iterate one container with indexes from another.
Drop LookupIterator.hpp in to your include path and you should be good to go.
const std::vector<int> lookup_vector = { 0, 2 };
const std::vector<int> data = { 10, 20, 30 };
for (const auto& x : lookup(data, lookup_vector)) {
std::cout << x << '\n';
}
will output
10
30
Data can be anything that specifies an operator[]
, such as map
std::vector<char> lookup_vector = { 'b', 'c' };
std::map<char, int> data = { {'a', 10}, {'b', 20}, {'c', 30} };
for (const auto& x : lookup(data, lookup_vector)) {
std::cout << x << '\n';
}
will output
20
30
lookup
also defaults to a vector, such that initialisation lists can be used
const std::vector<int> data = { 10, 20, 30 };
for (const auto& x : lookup(data, { 0, 2 })) {
std::cout << x << '\n';
}
will output
10
30
lookup(Src src, Lookup lookup)
Lookup
must be allow either++
--
operatorsSrc
must have anoperator[]