Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
February 27, 2008 tango list | ||||
---|---|---|---|---|
| ||||
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 ????. |
February 27, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to quest | 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.
|
February 27, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | 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.
|
February 27, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | 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();
}
|
February 27, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | 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
|
February 28, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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.
|
February 28, 2008 Re: tango list | ||||
---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | "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
|
Copyright © 1999-2021 by the D Language Foundation