digitalmars.D - getting keytype/valuetype in array
- Carlos Santander (25/25) Aug 31 2005 David Medlock recently posted a code for mixin in opApply, opIndex and
- Regan Heath (5/28) Aug 31 2005 The idea is close to implicit template instatiation. I can't help but
- Carlos Santander (17/58) Sep 01 2005 I agree it's a bit related, but not fully: with implicit template instan...
- Regan Heath (9/61) Sep 01 2005 I understand your proposal.
- Ben Hinkle (5/28) Sep 01 2005 I agree it would be nice. In MinTL I've been using the names IndexType a...
- Chris Sauls (7/38) Sep 01 2005 Currently one can use an array with a template defined such as:
David Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think? -- Carlos Santander Bernal
Aug 31 2005
The idea is close to implicit template instatiation. I can't help but think it could somehow be combined with that, if/when we get it. Regan On Wed, 31 Aug 2005 22:26:20 -0500, Carlos Santander <csantander619 gmail.com> wrote:David Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think?
Aug 31 2005
Regan Heath escribió:The idea is close to implicit template instatiation. I can't help but think it could somehow be combined with that, if/when we get it. Regan On Wed, 31 Aug 2005 22:26:20 -0500, Carlos Santander <csantander619 gmail.com> wrote:I agree it's a bit related, but not fully: with implicit template instantiation, the compiler has to deduce the types from the parameters, but what I'm proposing here is adding a couple of properties to arrays. Maybe a better idea would be like this: template applyThis( alias var ) { alias typeof(var).keytype K; alias typeof(var).valuetype V; ... } So you could do: (int[]).keytype key; //key would be size_t (char[][]).valuetype value; //value would be char[] typeof(value).valuetype anotherKey; //anotherValue would be char -- Carlos Santander BernalDavid Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think?
Sep 01 2005
On Thu, 01 Sep 2005 18:58:49 -0500, Carlos Santander <csantander619 gmail.com> wrote:Regan Heath escribió:I understand your proposal. My comment was that I think implicit template instantiation is a better way to get what you want. I imagined something like "Chris Sauls" proposed in this thread. Of course your proposal allows other things as well, as you've shown here, so it may be useful to have both. ReganThe idea is close to implicit template instatiation. I can't help but think it could somehow be combined with that, if/when we get it. Regan On Wed, 31 Aug 2005 22:26:20 -0500, Carlos Santander <csantander619 gmail.com> wrote:I agree it's a bit related, but not fully: with implicit template instantiation, the compiler has to deduce the types from the parameters, but what I'm proposing here is adding a couple of properties to arrays. Maybe a better idea would be like this: template applyThis( alias var ) { alias typeof(var).keytype K; alias typeof(var).valuetype V; ... } So you could do: (int[]).keytype key; //key would be size_t (char[][]).valuetype value; //value would be char[] typeof(value).valuetype anotherKey; //anotherValue would be charDavid Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think?
Sep 01 2005
"Carlos Santander" <csantander619 gmail.com> wrote in message news:df5tmk$6vp$2 digitaldaemon.com...David Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think?I agree it would be nice. In MinTL I've been using the names IndexType and ValueType. For lists and arrays which use integer indexing IndexType is size_t.
Sep 01 2005
Carlos Santander wrote:David Medlock recently posted a code for mixin in opApply, opIndex and opIndexAssign. Having done the same code myself, a question popped to my head. Notice how the mixin is defined and then used: template applyThis( K, V, alias var ) { ... } class MyWidgets { Widget[char[]] lookup; mixin applyThis!( char[], Widget, lookup ); } My question is, could there be a way for getting K and V from var? Maybe something like this: template applyThis( alias var ) { alias var.keytype K; alias var.valuetype V; ... } Which could then be used in a simpler way: mixin applyThis!(lookup); These two properties could be defined for all arrays, not just AAs. Also, if someone wanted to define her own collection, she'd have to also define those types/properties. What do you guys think?Currently one can use an array with a template defined such as: And T will be set to the array's value type. So maybe for AA's we could use: Or something similar. -- Chris Sauls
Sep 01 2005