Skip to content

ThomasMonkman/lookup-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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[]

About

Iterate one container with indexes from another

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published