digitalmars.D.learn - multiple opApply functions?
- Jason House <jason.james.house gmail.com> May 20 2007
- Daniel Keep <daniel.keep.lists gmail.com> May 21 2007
- Daniel Keep <daniel.keep.lists gmail.com> May 21 2007
- Jason House <jason.james.house gmail.com> May 21 2007
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> May 21 2007
- Bill Baxter <dnewsgroup billbaxter.com> May 22 2007
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> May 22 2007
Is it possible to have multiple opApply calls for a single class? The
following code almost compiles. It appears gdc 0.23 (implementing dmd
1.007) tries to match against the first opApply instead of finding the
correct match (the 2nd opApply).
The compiler knows the first one is a bad match, gives an error, and
exits. How do I overcome this?
interface X(T,P){
int opApply(int delegate(P));
int opApply(int delegate(T));
int opApply(int delegate(P,T));
}
class Y(T,P) : public X(T,P){
...
}
int main(){
Y y = new Y!(int,float)(...);
foreach(int x; y){
...
}
}
May 20 2007
Jason House wrote:Is it possible to have multiple opApply calls for a single class? The following code almost compiles. It appears gdc 0.23 (implementing dmd 1.007) tries to match against the first opApply instead of finding the correct match (the 2nd opApply). The compiler knows the first one is a bad match, gives an error, and exits. How do I overcome this? interface X(T,P){ int opApply(int delegate(P)); int opApply(int delegate(T)); int opApply(int delegate(P,T)); } class Y(T,P) : public X(T,P){ ... } int main(){ Y y = new Y!(int,float)(...); foreach(int x; y){ ... } }
Random thought: aren't those delegates supposed to be "int delegate(ref P)"? I'm pretty sure DMD is touchy about that... -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 21 2007
Just realised; if that version of gdc only implements D v1.007, you
might need to try "inout" instead of "ref".
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
May 21 2007
Daniel Keep wrote:Just realised; if that version of gdc only implements D v1.007, you might need to try "inout" instead of "ref".
That worked, but now I'm confused... isn't inout the default way of passing parameters into functions? I thought inout was assumed.
May 21 2007
"Jason House" <jason.james.house gmail.com> wrote in message news:f2tj95$2llq$1 digitalmars.com...Daniel Keep wrote:Just realised; if that version of gdc only implements D v1.007, you might need to try "inout" instead of "ref".
That worked, but now I'm confused... isn't inout the default way of passing parameters into functions? I thought inout was assumed.
No; inout is "by reference." The default is in, which means "by value."
May 21 2007
Jarrett Billingsley wrote:"Jason House" <jason.james.house gmail.com> wrote in message news:f2tj95$2llq$1 digitalmars.com...Daniel Keep wrote:Just realised; if that version of gdc only implements D v1.007, you might need to try "inout" instead of "ref".
passing parameters into functions? I thought inout was assumed.
No; inout is "by reference." The default is in, which means "by value."
But if you're passing a reference (a class instance or array) then "by value" means the pointer to the class or array is passed by value. Modifications to the contents are visible to the caller, modification of the pointer itself is not. --bb
May 22 2007
"Bill Baxter" <dnewsgroup billbaxter.com> wrote in message news:f2uij0$2a3e$1 digitalmars.com...But if you're passing a reference (a class instance or array) then "by value" means the pointer to the class or array is passed by value. Modifications to the contents are visible to the caller, modification of the pointer itself is not. --bb
Good clarification.
May 22 2007









Daniel Keep <daniel.keep.lists gmail.com> 