digitalmars.D.learn - Checking if UFCS function exists for a specific type
- Rory McGuire (11/11) Aug 29 2013 Hi all,
- Rory McGuire (16/27) Aug 29 2013 forum posted when I hit tab. Meant to ask:
- Rory McGuire (5/34) Aug 30 2013 I suppose I can avoid the implicit casts for function lookup by
Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; // would be nice if we could use ParameterTypeTuple to get the first arg and check for exact type match return __traits(compiles, mixin(member ~"(v)")); }
Aug 29 2013
On Thursday, 29 August 2013 at 21:06:04 UTC, Rory McGuire wrote:Hi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; // would be nice if we could use ParameterTypeTuple to get the first arg and check for exact type match return __traits(compiles, mixin(member ~"(v)")); }forum posted when I hit tab. Meant to ask: Is there a way to make sure that the compiler is not implicitly casting T? Currently it returns true for bool, enum, int etc... even if the only function available is for an int. I also have: template hasUFCSmember(T, string member) { enum hasUFCSmember = __traits(compiles, mixin(member ~"(T.init)")); } But it doesn't work for types such as string[string] because T.init is null. Any help will be greatly appreciated. Thanks, R
Aug 29 2013
On Thursday, 29 August 2013 at 21:10:41 UTC, Rory McGuire wrote:On Thursday, 29 August 2013 at 21:06:04 UTC, Rory McGuire wrote:I suppose I can avoid the implicit casts for function lookup by using Typedef. Thanks, RHi all, I've got this little ctfe template function that checks if a function called member with first argument T exists. Its for checking if a type has a custom encoder. bool hasUFCSmember(T, string member)() { T v; // would be nice if we could use ParameterTypeTuple to get the first arg and check for exact type match return __traits(compiles, mixin(member ~"(v)")); }forum posted when I hit tab. Meant to ask: Is there a way to make sure that the compiler is not implicitly casting T? Currently it returns true for bool, enum, int etc... even if the only function available is for an int. I also have: template hasUFCSmember(T, string member) { enum hasUFCSmember = __traits(compiles, mixin(member ~"(T.init)")); } But it doesn't work for types such as string[string] because T.init is null. Any help will be greatly appreciated. Thanks, R
Aug 30 2013