Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created June 24, 2013 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bananu7/df047a7ba5ce470fa02a to your computer and use it in GitHub Desktop.
Save bananu7/df047a7ba5ce470fa02a to your computer and use it in GitHub Desktop.
Uh.
template<typename A, typename B>
class ArrayRunner {
std::vector<A> a;
std::vector<B> b;
std::vector<bool> arr;
public:
/*
A1 A2 AN
B1 x o ...
B2 o ...
BN x ...
*/
ArrayRunner(std::vector<GLenum> _a, std::vector<GLenum> _b, std::vector<bool> _arr)
: a(boost::move(_a))
, b(_b)
, arr(_arr)
{
if (a.size() * b.size() != arr.size())
throw std::runtime_error("The size of boolean array must be the size of the header vectors multiplied!");
}
bool arr_n (int x, int y) {
return arr.at(x + y * a.size());
}
void map(boost::function<void(A,B)> & fn) {
for (std::vector<B>::size_type bi = 0; bi < b.size(); ++bi) {
for (std::vector<A>::size_type ai = 0; ai < a.size(); ++ai) {
if (arr_n(ai, bi)) {
fn(a[ai], b[bi]);
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment