Issue 15264 - opDispatch cannot implement range primitives
Summary: opDispatch cannot implement range primitives
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: x86_64 Linux
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-30 01:38 UTC by ryan
Modified: 2024-12-07 13:35 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ryan 2015-10-30 01:38:28 UTC
If you use opDispatch to implement range primitives, isInputRange passes yet it cannot be used in foreach loops:

---
import std.range;

struct R {
  auto vals = iota(0, 5);
  auto opDispatch(string s)() { return mixin("vals."~s); }

  // uncomment to pass:
  //auto front() { return vals.front; }
  //auto popFront() { return vals.popFront; }
  //auto empty() { return vals.empty; }
}

// R is an input range, but cannot be used in foreach:
static assert(isInputRange!R);                               // pass
static assert(__traits(compiles, { foreach(v ; R()) { } })); // fail
---

We either need to allow foreach via opDispatched range primitives or have is*Range return false in this case.

Personally, I would like to see foreach work in this case, though there may be concerns over 'accidental' range implementation:
http://forum.dlang.org/thread/tociqzmmryxyggzypmdk@forum.dlang.org
Comment 1 dlangBugzillaToGithub 2024-12-07 13:35:54 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17315

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB