August 31, 2012 popFront with input variables | ||||
---|---|---|---|---|
| ||||
Hello all, Is it considered legit in any circumstances for popFront to take an input variable (e.g. a random number generator)? Or is it required always to have no input variables? Thanks & best wishes, -- Joe |
August 31, 2012 Re: popFront with input variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joseph Rushton Wakeling | Joseph Rushton Wakeling:
> Is it considered legit in any circumstances for popFront to take an input variable (e.g. a random number generator)? Or is it required always to have no input variables?
popFront is meant to be called by foreach, or to be verified by
the isSomething compile-time tests of std.range. In both cases if
popFront takes an argument, it doesn't work. So I think it's not
a good idea.
struct Foo {
enum bool empty = false;
@property int front() { return 1; }
void popFront(int x) {}
//void popFront() {}
}
void main() {
import std.stdio;
foreach (i; Foo())
writeln(i);
}
temp.d(9): Error: function temp.Foo.popFront (int x) is not
callable using argument types ()
temp.d(9): Error: expected 1 function arguments, not 0
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation