Skip to content

Latest commit

 

History

History
58 lines (51 loc) · 1.47 KB

README.md

File metadata and controls

58 lines (51 loc) · 1.47 KB

lookup-iterator

Branch Status
Master Master

A single header iterator that allows you to iterate one container with indexes from another.

Install:

Drop LookupIterator.hpp in to your include path and you should be good to go.

Examples:

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

Requirements

lookup(Src src, Lookup lookup)
  • Lookup must be allow either ++ -- operators
  • Src must have an operator[]