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

vector<bool> and groupby #58

Open
miguel-negrao opened this issue Jun 4, 2019 · 2 comments
Open

vector<bool> and groupby #58

miguel-negrao opened this issue Jun 4, 2019 · 2 comments
Assignees
Labels

Comments

@miguel-negrao
Copy link

Hi

I'm getting another strange behaviour:

  vector<bool> v{true, true, false, false,false, true, true};
  for (auto &&x: iter::groupby(v,[](auto b){return b;})) {
    cout << "group: ";
    for (auto &&g: x.second)
      cout << g << " ";
    cout << endl;
  }

prints

group: 1 1 0 0 0 1 1 

yet

  vector<int> v{5,5,5,3,3};
  for (auto &&x: iter::groupby(v,[](auto b){return b;})) {
    cout << "group: ";
    for (auto &&g: x.second)
      cout << g << " ";
    cout << endl;
  }

prints

group: 5 5 5 
group: 3 3

Is there a reason why it shouldn't work with bool ?

@ryanhaining
Copy link
Owner

This is definitely a more insidious bug surely related to std::vector being a specialization. It should work with bool. Looking into it

@ryanhaining ryanhaining self-assigned this Jun 8, 2019
@ryanhaining ryanhaining added the bug label Jun 8, 2019
@ryanhaining
Copy link
Owner

Still trying to figure out exactly what is going on here, but it looks to be related to std::vector<bool>::operator*'s proxy object. If you change your lambda to take bool instead of auto the code works as expected.

It doesn't work, however with the default identity functionality of groupby(v), so I've got an issue there too.

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

No branches or pull requests

2 participants