Google video about consepts

Downs default_357-line at yahoo.de
Thu Apr 5 11:12:44 PDT 2007


Knud Soerensen wrote:
> Hi 
> 
> I found this interesting google video.
> 
> Concepts: Extending C++ Templates For Generic Programming
> http://video.google.com/videoplay?docid=-1790714981047186825&hl=en

Somewhat related to that, if you want to check if a template type implements some function without requiring interfaces, here's a quick template:

 > template funcmatch(T, char[] name, RetType, Parameters ...) {
 >   mixin("static assert(is(typeof(T."~name~")), \""~T.stringof~": Function "~name~" not implemented!\");");
 >   mixin("static assert(is(ReturnType!(T."~name~")==RetType), \""~T.stringof
 >     ~": Return type is \"~ReturnType!(T."~name~").stringof~\", should be \"~RetType.stringof);");
 >   mixin("static assert(is(ParameterTypeTuple!(T."~name~")==Parameters), \""~T.stringof
 >     ~": Function parameters are \"~ParameterTypeTuple!(T."~name~").stringof~\", "
 >     ~"should be \"~Parameters.stringof);");
 > }

use it like template foo(T) { mixin funcmatch!(T, "mustImplement", int, float, char[]); }
This will make sure T implements a int mustImplement(float, char[]) and output a helpful error message if it doesn't.

greetings -- downs



More information about the Digitalmars-d mailing list