opDispatch and template parameters
Guillaume B.
guillaume.b.spam at spam.ca
Tue Sep 14 17:41:29 PDT 2010
Simen kjaeraas wrote:
> Guillaume B. <guillaume.b.spam at spam.ca> wrote:
>
>> Hi,
>>
>> Is this usage of opDispatch supposed to work:
>>
>> ====
>> module test.d;
>>
>> import std.stdio;
>>
>> struct DispatchTest {
>> void opDispatch(string name, string otherName)() {
>> writeln(name, ":", otherName);
>> }
>> }
>>
>> void main() {
>> DispatchTest t;
>> //t.testName!("testOtherName")();
>> t.opDispatch!("testName", "testOtherName")();
>> }
>> ====
>> [...]
>
> Sorry for not noticing this post before. This is not a bug. The correct
> way to do what you want is this:
>
>
> module foo;
>
> import std.stdio;
>
> struct test {
> template opDispatch( string name ) {
> void opDispatch( string other )( ) {
> writeln( name, ", ", other );
> }
> }
> }
>
> void main( ) {
> test t;
> t.foo!( "Hey!" )( );
> }
>
Wow! That's a nice trick! Seems like I'll have to be carefull when defining
opDispatch!
Guillaume
More information about the Digitalmars-d
mailing list