dynamic classes and duck typing

Michel Fortin michel.fortin at michelf.com
Sun Nov 29 04:16:35 PST 2009


On 2009-11-29 06:14:21 -0500, "Simen kjaeraas" <simen.kjaras at gmail.com> said:

> That is because your opDispatch is instantiated no matter what the name
> is, but only does something sensible if it's foo. Try this:
> 
> string opDispatch( string name )( ) {
>    static if ( name == "foo" ) {
>      return "foo";
>    } else {
>      static assert( false, "Invalid member name." );
>    }
> }

Wouldn't this be even better?

	string opDispatch(string name)() if (name == "foo") {
		return "foo";
	}

I haven't tested that it works though.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list