templating operators
Brad Roberts
braddr at puremagic.com
Thu Mar 2 21:38:09 PST 2006
On Fri, 3 Mar 2006, Derek Parnell wrote:
> When I did this sort of thing I had to chnage the template name to be
> different to the member inside the template *and* I had to instantiate the
> member inside the class. The instantiation didn't surprise me but the
> naming conflict one did. Anyhow, replace ...
>
> template opIndex(T)
> {
> T opIndex(char[] key)
> {
> return unbox!(T)(_objects[key]);
> }
> }
>
> with ...
>
> template opIndex_T(T)
> {
> T opIndex(char[] key)
> {
> return unbox!(T)(_objects[key]);
> }
> }
> alias opIndex_T!(int).opIndex opIndex;
>
> and it should work now.
>
> --
> Derek
> (skype: derek.j.parnell)
> Melbourne, Australia
> "Down with mediocracy!"
> 3/03/2006 3:14:03 PM
This works wonderfully for opIndexAssign, but not so much for multiple
types of aliases for opIndex.
alias opIndex_T!(int).opIndex opIndex;
alias opIndex_T!(float).opIndex opIndex;
test.d(54): function alias opIndex called with argument types:
(char[3])
matches both:
test.ValueContainer.opIndex_T!(int).opIndex(char[])
and:
test.ValueContainer.opIndex_T!(float).opIndex(char[])
test.d(55): function alias opIndex called with argument types:
(char[3])
matches both:
test.ValueContainer.opIndex_T!(int).opIndex(char[])
and:
test.ValueContainer.opIndex_T!(float).opIndex(char[])
test.d(56): function expected before (), not 0 of type int
So close...
Brad
More information about the Digitalmars-d
mailing list