Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add where overload for range-based for #40

Open
mattkretz opened this issue Mar 1, 2017 · 2 comments
Open

Add where overload for range-based for #40

mattkretz opened this issue Mar 1, 2017 · 2 comments

Comments

@mattkretz
Copy link
Owner

Vc has this cool feature:

for (int i : where(mask)) {
  assert(mask[i]);
}

The idea is to iterate over the mask and do something at the indexes where the mask is set. This is very useful for switching vectorization direction or switching to scalar logic.
It could be extended to:

for (auto x : where(mask, vec)) {
  // basically x = vec[i] for all i where mask[i] is true
}

The latter seems less useful. You probably want at least a pair containing the index and the value. But in that case the added convenience compared to the first example is minimal.

@jensmaurer
Copy link
Collaborator

Hm... So have a const_iterator over a mask's elements. Do you have some code example where this is useful?

@mattkretz
Copy link
Owner Author

mattkretz commented Mar 5, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants