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

opDispatch cannot implement range primitives #17315

Open
dlangBugzillaToGithub opened this issue Oct 30, 2015 · 0 comments
Open

opDispatch cannot implement range primitives #17315

dlangBugzillaToGithub opened this issue Oct 30, 2015 · 0 comments
Labels
Arch:x86_64 Issues specific to x86_64 Druntime Specific to druntime OS:Linux P4 Severity:Enhancement

Comments

@dlangBugzillaToGithub
Copy link

ryan reported this on 2015-10-30T01:38:28Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=15264

CC List

Description

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
@thewilsonator thewilsonator added Severity:Enhancement Druntime Specific to druntime and removed enhancement labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 Druntime Specific to druntime OS:Linux P4 Severity:Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants