{"action":"opened","issue":{"url":"https://api.github.com/repos/ericniebler/range-v3/issues/1393","repository_url":"https://api.github.com/repos/ericniebler/range-v3","labels_url":"https://api.github.com/repos/ericniebler/range-v3/issues/1393/labels{/name}","comments_url":"https://api.github.com/repos/ericniebler/range-v3/issues/1393/comments","events_url":"https://api.github.com/repos/ericniebler/range-v3/issues/1393/events","html_url":"https://github.com/ericniebler/range-v3/issues/1393","id":538562373,"node_id":"MDU6SXNzdWU1Mzg1NjIzNzM=","number":1393,"title":"group_by becomes infinite loop if initial predicate yields false","user":{"login":"BRevzin","id":13238276,"node_id":"MDQ6VXNlcjEzMjM4Mjc2","avatar_url":"https://avatars2.githubusercontent.com/u/13238276?v=4","gravatar_id":"","url":"https://api.github.com/users/BRevzin","html_url":"https://github.com/BRevzin","followers_url":"https://api.github.com/users/BRevzin/followers","following_url":"https://api.github.com/users/BRevzin/following{/other_user}","gists_url":"https://api.github.com/users/BRevzin/gists{/gist_id}","starred_url":"https://api.github.com/users/BRevzin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BRevzin/subscriptions","organizations_url":"https://api.github.com/users/BRevzin/orgs","repos_url":"https://api.github.com/users/BRevzin/repos","events_url":"https://api.github.com/users/BRevzin/events{/privacy}","received_events_url":"https://api.github.com/users/BRevzin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-12-16T17:53:59Z","updated_at":"2019-12-16T17:53:59Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"From Conor Hoekstra on slack:\r\n\r\n```cpp\r\nstd::vector v = {1, 2, 3};\r\nauto g = v | group_by([](int, int){ return false; });\r\n```\r\n\r\nThis should provide a range of ranges of size 1: `[[1], [2], [3]]`. But what it does instead is provide an infinite range of empty ranges. \r\n\r\nOne possible fix in https://github.com/ericniebler/range-v3/blob/master/include/range/v3/view/group_by.hpp#L96-L105 is to do something like this:\r\n\r\n```cpp\r\nauto read() const\r\n{\r\n  auto second = ranges::next(cur_);\r\n  return views::concat(\r\n\t\t  subrange{cur_, second},\r\n\t\t  subrange{second, last_} | views::take_while(pred{cur_, fun_}));\r\n}\r\nvoid next()\r\n{\r\n  cur_ = find_if_not(ranges::next(cur_), last_, pred{cur_, fun_});\r\n}\r\n```\r\n\r\nThat is, unconditionally include `cur_` in the \"current range\" without a predicate check. This gives the correct result, but I'm not sure if it's actually the \"correct\" fix or if there's a better way to implement something like this. \r\n\r\n`group_by` already requires `forward_range` so at least this wouldn't add any extra requirements. "}}
{"actor":{"display_login":"BRevzin"}}