import typetraits
type MyObj = object
type MyObj2 = object
proc test( x:int ) = discard
proc test( x:MyObj ) = discard
template hasTestProc(x:typed) =
when( compiles( test(x) ) ):
echo typetraits.name( type(x) ), " has Test Proc"
else:
echo typetraits.name( type(x) ), " doesn't have Test Proc"
hasTestProc( 0 )
hasTestProc( "abc" )
hasTestProc( MyObj() )
hasTestProc( MyObj2() )
aW1wb3J0IHR5cGV0cmFpdHMKCnR5cGUgTXlPYmogPSBvYmplY3QKdHlwZSBNeU9iajIgPSBvYmplY3QKCnByb2MgdGVzdCggeDppbnQgKSA9IGRpc2NhcmQKcHJvYyB0ZXN0KCB4Ok15T2JqICkgPSBkaXNjYXJkCgp0ZW1wbGF0ZSBoYXNUZXN0UHJvYyh4OnR5cGVkKSA9CiAgICB3aGVuKCBjb21waWxlcyggdGVzdCh4KSApICk6CiAgICAgICAgZWNobyB0eXBldHJhaXRzLm5hbWUoIHR5cGUoeCkgKSwgIiBoYXMgVGVzdCBQcm9jIgogICAgZWxzZToKICAgICAgICBlY2hvIHR5cGV0cmFpdHMubmFtZSggdHlwZSh4KSApLCAiIGRvZXNuJ3QgaGF2ZSBUZXN0IFByb2MiCgpoYXNUZXN0UHJvYyggMCApIApoYXNUZXN0UHJvYyggImFiYyIgKSAKaGFzVGVzdFByb2MoIE15T2JqKCkgKQpoYXNUZXN0UHJvYyggTXlPYmoyKCkgKSA=