Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
August 08, 2003 Another template question | ||||
---|---|---|---|---|
| ||||
What am I doing wrong? template Foo(T) { struct Bar { T fooBar; } } alias instance Foo(Fu) FooT; struct Fu { FooT.Bar x; } no property 'Bar' for type 'instance Foo(Fu )' |
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sokol | On Thu, 07 Aug 2003 23:51:32 -0400, Chris Sokol wrote:
> template Foo(T) {
> struct Bar {
> T fooBar;
> }
Oops, I meant to say T* fooBar;
|
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sokol | Chris Sokol wrote:
> What am I doing wrong?
>
> template Foo(T) {
> struct Bar {
> T fooBar;
> }
> }
>
> alias instance Foo(Fu) FooT;
>
> struct Fu {
> FooT.Bar x;
> }
>
> no property 'Bar' for type 'instance Foo(Fu )'
Wrong error message, but this is the same thing as doing:
struct x
{
struct y
{
x xitem;
}
y yitem;
}
So it has an infinite size. Use "class" instead, or pointers.
|
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | On Fri, 08 Aug 2003 00:35:19 -0400, Burton Radons wrote:
> So it has an infinite size. Use "class" instead, or pointers.
Yeah, I meant to use a pointer. Typo. But that is the error that I get
with T* fooBar inside the template.
|
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Sokol | "Chris Sokol" <chris@echosproject.org> wrote in message news:bgv6f0$1mic$1@digitaldaemon.com... > What am I doing wrong? > > no property 'Bar' for type 'instance Foo(Fu )' I had a play with this ..... template Foo(T) { struct Bar { T * fooBar; } } alias instance Foo(Fu).Bar FooT; struct Fu { FooT x; } int main() { Fu f; return 0; } now it reports main.d(7): size of type instance Foo(Fu ).Bar is not known but ................................. template Foo(T) { struct Bar { T * fooBar; } } struct Fu { instance Foo(Fu).Bar x; } int main() { Fu f; return 0; } WORKS |
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | and I tried a couple of other arrangements each has its own unique error .... template Foo(T) { struct Bar { T * fooBar; } } instance Foo(Fu).Bar foo_bar; struct Fu { foo_bar x; } int main() { Fu f; return 0; } //give the error //@test_005.d(9): foo_bar is used as a type // template Foo(T) { struct Bar { T * fooBar; } } instance Foo(Fu) foo_fu; struct Fu { foo_fu.Bar x; } int main() { Fu f; return 0; } // gives the error //@test_004.d(9): identifier 'Bar' of 'foo_fu.Bar' is not defined // "Mike Wynn" <mike.wynn@l8night.co.uk> wrote in message news:bgvbr5$1rmo$1@digitaldaemon.com... > > "Chris Sokol" <chris@echosproject.org> wrote in message news:bgv6f0$1mic$1@digitaldaemon.com... > > What am I doing wrong? > > > > no property 'Bar' for type 'instance Foo(Fu )' > > I had a play with this ..... > > template Foo(T) { > struct Bar { > T * fooBar; > } > } > > alias instance Foo(Fu).Bar FooT; > struct Fu { > FooT x; > } > > int main() { > Fu f; > return 0; > } > > now it reports > main.d(7): size of type instance Foo(Fu ).Bar is not known > > but ................................. > > template Foo(T) { > struct Bar { > T * fooBar; > } > } > > struct Fu { > instance Foo(Fu).Bar x; > } > > int main() { > Fu f; > return 0; > } > > WORKS > > |
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | Ah, thank you.
On Fri, 08 Aug 2003 01:30:51 -0400, Mike Wynn wrote:
> "Chris Sokol" <chris@echosproject.org> wrote in message news:bgv6f0$1mic$1@digitaldaemon.com...
>> What am I doing wrong?
>>
>> no property 'Bar' for type 'instance Foo(Fu )'
>
> I had a play with this .....
>
> template Foo(T) {
> struct Bar {
> T * fooBar;
> }
> }
> }
> alias instance Foo(Fu).Bar FooT;
> struct Fu {
> FooT x;
> }
> }
> int main() {
> Fu f;
> return 0;
> }
> }
> now it reports
> main.d(7): size of type instance Foo(Fu ).Bar is not known
>
> but .................................
>
> template Foo(T) {
> struct Bar {
> T * fooBar;
> }
> }
> }
> struct Fu {
> instance Foo(Fu).Bar x;
> }
> }
> int main() {
> Fu f;
> return 0;
> }
> }
> WORKS
|
August 08, 2003 Re: Another template question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | On Fri, 08 Aug 2003 01:38:41 -0400, Mike Wynn wrote:
> and I tried a couple of other arrangements each has its own unique error ....
>
> template Foo(T) {
> struct Bar {
> T * fooBar;
> }
> }
> }
> instance Foo(Fu).Bar foo_bar;
> struct Fu {
> foo_bar x;
> }
> }
> int main() {
> Fu f;
>
> return 0;
> }
> }
> //give the error
> //@test_005.d(9): foo_bar is used as a type //
I have a favorite set of c++ list and tree templates that I did, which I want to port to D as a learning experience. They work without performing any allocation; the nodes which are to be placed in the list need to have linkage already present. They go kind of like this:
template<typename T>
class List {
struct Node {
T* prev;
T* next;
};
// all sorts of stuff
};
typedef List<struct Element> ElementList;
struct Element {
ElementList::Node listNode;
// blah blah blah
};
Is this the proper D-like approach? I definitely do not want to require the List to allocate it's own linkage; one of the things this is used for is implementing malloc / free.
Having to do
struct Element {
instance ListT(Element).Node listNode;
};
feels somewhat unweildy; is there no way to something closer to my original example or the typedef approach above?
|
Copyright © 1999-2021 by the D Language Foundation