digitalmars.D - something cool: templated typedefs
- Sean Kelly (32/32) Jul 22 2004 It just occurred to me this morning to see if I could get templated type...
- Sha Chancellor (19/48) Jul 22 2004 Why is it you can do imap.key and imap.val. Shouldn't this need to be
- Sean Kelly (24/65) Jul 22 2004 The key is the section on implicit template properties. The text reads:...
It just occurred to me this morning to see if I could get templated typedefs to work in D. This is at the top of my wish list for C++ and I was excited to see that they already work in D. Here's an example: prints: char char int char I'm really starting to like the way D handles templates. This auto-collapsing of template names is starting to look *very* useful. Sean
Jul 22 2004
In message <cdovkl$v8f$1 digitaldaemon.com> Sean Kelly <sean f4.ca> wrote:that they already work in D. Here's an example: prints: char char int char I'm really starting to like the way D handles templates. This auto-collapsing of template names is starting to look *very* useful.Why is it you can do imap.key and imap.val. Shouldn't this need to be done like: IntMap!(char).IntMap imap = new IntMap!(char).IntMap. Or is there some special thing going on when there's an alias to something with the same name as a template? I thought templates had their own namespace.. What's going on here seems very mystical to me. Right from the template specification: TemplateInstance: template TFoo(T) { alias T* t; } ... TFoo!(int).t x; // declare x to be of type int* A template instantiation can be aliased: template TFoo(T) { alias T* t; } alias TFoo!(int) abc; abc.t x; // declare x to be of type int*
Jul 22 2004
In article <cdp9pi$13ns$1 digitaldaemon.com>, Sha Chancellor says...In message <cdovkl$v8f$1 digitaldaemon.com> Sean Kelly <sean f4.ca> wrote:The key is the section on implicit template properties. The text reads: "if a template has exactly one member in it, and the name of that member is the same as the template name, that member is assumed to be referred to in a template instantiation." ie. can be called as: ie. it's the same as doing: The important thing to note is that the standard mentions no restrictions on what the member has to be. So my example: would normally be called as: but collapses to: Seanthat they already work in D. Here's an example: prints: char char int char I'm really starting to like the way D handles templates. This auto-collapsing of template names is starting to look *very* useful.Why is it you can do imap.key and imap.val. Shouldn't this need to be done like: IntMap!(char).IntMap imap = new IntMap!(char).IntMap. Or is there some special thing going on when there's an alias to something with the same name as a template? I thought templates had their own namespace.. What's going on here seems very mystical to me.
Jul 22 2004