www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - tango list

reply quest <quest questx.com> writes:
hi,

i would like to hand over some LinkSeq list to some funktions. what would be 
function header??


void testfunc(???? lists, int bolony) { ....  }

seems like i can't use LinkSeq for the ????.
Feb 27 2008
parent reply Christopher Wright <dhasenan gmail.com> writes:
quest wrote:
 hi,
 
 i would like to hand over some LinkSeq list to some funktions. what would be 
 function header??
 
 
 void testfunc(???? lists, int bolony) { ....  }
 
 seems like i can't use LinkSeq for the ????.
// Use a list of any type of element void testfunc(T)(ListSeq!(T) list, int bologna) {} Unfortunately, you won't be able to put that in an interface.
Feb 27 2008
next sibling parent quest <quest <quest questx.com>> writes:
thank you, that did the trick!

Christopher Wright Wrote:

 quest wrote:
 hi,
 
 i would like to hand over some LinkSeq list to some funktions. what would be 
 function header??
 
 
 void testfunc(???? lists, int bolony) { ....  }
 
 seems like i can't use LinkSeq for the ????.
// Use a list of any type of element void testfunc(T)(ListSeq!(T) list, int bologna) {} Unfortunately, you won't be able to put that in an interface.
Feb 27 2008
prev sibling next sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Christopher Wright wrote:
 quest wrote:
 hi,

 i would like to hand over some LinkSeq list to some funktions. what 
 would be function header??


 void testfunc(???? lists, int bolony) { ....  }

 seems like i can't use LinkSeq for the ????.
// Use a list of any type of element void testfunc(T)(ListSeq!(T) list, int bologna) {} Unfortunately, you won't be able to put that in an interface.
Why not? interface ResultCollector { void notify(Result r); void notify(Seq!(Result) results); Seq!(Result) getResults(); }
Feb 27 2008
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Robert Fraser wrote:
 Christopher Wright wrote:
 quest wrote:
 hi,

 i would like to hand over some LinkSeq list to some funktions. what 
 would be function header??


 void testfunc(???? lists, int bolony) { ....  }

 seems like i can't use LinkSeq for the ????.
// Use a list of any type of element void testfunc(T)(ListSeq!(T) list, int bologna) {} Unfortunately, you won't be able to put that in an interface.
Why not? interface ResultCollector { void notify(Result r); void notify(Seq!(Result) results); Seq!(Result) getResults(); }
You can't put a template in an interface, just a particular instantiation of one, as you've done there. Try it with void notify(Result)(Seq!(Result) results); I'm not sure if it's even possible to make that work. It basically says the interface contains a family of functions and you aren't sure which ones yet. 'Course you *can* make a templated interface: interface ResultCollector(Result) { void notify(Result r); void notify(Seq!(Result) results); Seq!(Result) getResults(); } --bb
Feb 27 2008
parent Christopher Wright <dhasenan gmail.com> writes:
Bill Baxter wrote:
 You can't put a template in an interface, just a particular 
 instantiation of one, as you've done there.  Try it with
 
        void notify(Result)(Seq!(Result) results);
 
 I'm not sure if it's even possible to make that work.  It basically says 
 the interface contains a family of functions and you aren't sure which 
 ones yet.
It can be made to work, but not in D, at least not right now. You basically need a very wimpy template -- hereafter a 'generic' -- that doesn't do any compile-time reflection and doesn't call any templates (aside from generics). That would suffice for collections classes, except for requiring a hash function. In that case, the generic is equivalent to Java's generics: it just saves you from boxing and unboxing. I'm not sure how useful that is, though.
Feb 27 2008
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Christopher Wright" wrote
 quest wrote:
 hi,

 i would like to hand over some LinkSeq list to some funktions. what would 
 be function header??


 void testfunc(???? lists, int bolony) { ....  }

 seems like i can't use LinkSeq for the ????.
// Use a list of any type of element void testfunc(T)(ListSeq!(T) list, int bologna) {} Unfortunately, you won't be able to put that in an interface.
you can, but not in the way you are saying: interface myinterface(T) { void testfunc(ListSeq!(T) list, int balogna); } In fact, all the tango containers implement interfaces like this. -Steve
Feb 28 2008