parameter type tuple or alias for std.traits templates ?
Guillaume Chatelet
chatelet.guillaume at gmail.com
Sat Jun 23 01:48:45 PDT 2012
On 06/23/12 01:05, Timon Gehr wrote:
>
> Yes there is, but I have argued that this is a bug in the past. With
> DMD, the (func...) accepts built-in types, while the (alias func) does
> not.
Ok got it, the following won't compile I agree.
template isInt(alias T) {
enum bool isInt = is(T==int);
}
void main(){
static assert(isInt!int);
}
So I understand the following functions have to go the variadic way
because you want an answer at compile time and not a compiler error
template isFunctionPointer(T...)
template isDelegate(T...)
template isSomeFunction(T...)
template isCallable(T...)
template isAbstractFunction(method...)
template mangledName(sth...)
Nevertheless the following templates are all requiring 'func.length == 1
&& isCallable!func'
template ReturnType(func...)
template ParameterTypeTuple(func...)
template ParameterStorageClassTuple(func...)
template functionAttributes(func...)
template functionLinkage(func...)
template variadicFunctionStyle(func...)
template FunctionTypeOf(func...)
So they won't instantiate if you pass a built-in type anyway. Using an
'alias' instead of a 'func...' would make it clear that :
* you can't pass a built-in type in
* the template is requiring exactly one argument
As a user, I find it odd that ReturnType takes a TypeTuple rather than
an alias. 'func...' basically means 'I will accept a tuple of functions'
which is then restricted in the if clause to the case where func.length==1.
--
Guillaume
More information about the Digitalmars-d
mailing list