D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20496 - chunkby should support ref predicates
Summary: chunkby should support ref predicates
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-01-10 04:40 UTC by Steven Schveighoffer
Modified: 2020-04-26 16:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2020-01-10 04:40:04 UTC
auto r = [1,1,1,2,2,2,3,3,3];

writeln(r.chunkBy!((ref e1, ref e2) => e1 == e2));

Error: static assert:  "chunkBy expects either a binary predicate or a unary predicate on range elements of type: int"

The issue is that the test is using ElementType!Range.init as the parameters to the binary function. A workaround is to use auto ref (as the actual usage will be with lvalues).
Comment 1 Dlang Bot 2020-04-26 01:21:18 UTC
@MoonlightSentinel created dlang/phobos pull request #7459 "Fix Issue 20496 - chunkby should support ref predicate" fixing this issue:

- Fix Issue 20496 - chunkby should support ref predicate
  
  Provide an lvalue when checking the predicate

https://github.com/dlang/phobos/pull/7459
Comment 2 Dlang Bot 2020-04-26 02:28:53 UTC
dlang/phobos pull request #7459 "Fix Issue 20496 - chunkby should support ref predicate" was merged into master:

- 8fd3b6d3a538ed347855b3fb046028b2f195bda6 by MoonlightSentinel:
  Fix Issue 20496 - chunkby should support ref predicate
  
  Provide an lvalue when checking the predicate

https://github.com/dlang/phobos/pull/7459
Comment 3 Steven Schveighoffer 2020-04-26 16:53:17 UTC
Thanks! Now I just have to remember which code I added this workaround to... ;)