On Thursday, 26 January 2017 at 11:32:09 UTC, ZombineDev wrote:
Anyway, another solution is to use refRange:
void main() {
import std.range : refRange;
S s;
auto p = refRange();
foreach(i; p)
writeln(i);
}
That way you don't need to dereference 'p' everytime you want
On Thursday, 26 January 2017 at 12:03:39 UTC, guest wrote:
On Thursday, 26 January 2017 at 11:32:09 UTC, ZombineDev wrote:
Not sure if this is a bug in isInputRange or foreach, but they
should work consistently.
Copy/paste from primitives.d:
template isInputRange(R)
{
enum bool
On Thursday, 26 January 2017 at 11:32:09 UTC, ZombineDev wrote:
Not sure if this is a bug in isInputRange or foreach, but they
should work consistently.
Copy/paste from primitives.d:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r =
On Wednesday, 25 January 2017 at 16:15:49 UTC, Las wrote:
So the reference says that (when range has the properties)
`foreach (e; range) { ... }` is equivalent to:
for (auto __r = range; !__r.empty; __r.popFront())
{
auto e = __r.front;
...
}
Though this isn't always true, as when I
On Thursday, January 26, 2017 09:05:17 Las via Digitalmars-d wrote:
> On Wednesday, 25 January 2017 at 20:22:54 UTC, Jonathan M Davis
>
> wrote:
> > It only matters if you're trying to define the range primitives
> > for your range as free functions for some reason. Just put them
> > on the type
On Wednesday, 25 January 2017 at 16:15:49 UTC, Las wrote:
then I can do this:
void main() {
S s;
auto p =
p.popFront;
writeln(p.front);
}
But not this:
void main() {
S s;
auto p =
foreach(i; p)
writeln(i);
}
p.popFront
On Wednesday, 25 January 2017 at 20:22:54 UTC, Jonathan M Davis
wrote:
It only matters if you're trying to define the range primitives
for your range as free functions for some reason. Just put them
on the type itself and be done with it. The only reason that
wouldn't work would be if you
On Wednesday, January 25, 2017 16:15:49 Las via Digitalmars-d wrote:
> So the reference says that (when range has the properties)
> `foreach (e; range) { ... }` is equivalent to:
> for (auto __r = range; !__r.empty; __r.popFront())
> {
> auto e = __r.front;
> ...
> }
>
> Though this
So the reference says that (when range has the properties)
`foreach (e; range) { ... }` is equivalent to:
for (auto __r = range; !__r.empty; __r.popFront())
{
auto e = __r.front;
...
}
Though this isn't always true, as when I use this struct:
struct S {
int front = 10;