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

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?

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?

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 Bernal

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?

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

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.
Regan

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.

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:
# template Foo (T :T[]) { ... }
And T will be set to the array's value type. So maybe for AA's we could use:
# templtae Foo (alias ARR :VALUE[KEY]) { ... }
Or something similar.
-- Chris Sauls