如何从函数类型中删除属性?

How to remove the attributes from a function type?

在以下示例中,第一个测试因函数类型属性而失败。第二个测试覆盖了这个问题,但它在语法上太重了。

import std.traits;

bool test1(T)()
{
    // clean but does not work !
    alias Fun = bool function(dchar);
    return (is(Unqual!T == Fun));    
}

bool test2(T)()
{
    // super heavy !
    return (isSomeFunction!T &&  is(ReturnType!T == bool) &&
        Parameters!T.length == 1 && is(Parameters!T[0] == dchar)
    );
}

void main(string[] args)
{
    import std.ascii: isAlpha;
    assert(test1!(typeof(&isAlpha)));
    assert(test2!(typeof(&isAlpha)));       
}

有没有办法删除属性,就像 Unqual 对存储所做的那样 类?

看看这个:http://dlang.org/phobos/std_traits.html#SetFunctionAttributes

std.traits.SetFunctionAttributes

 alias ExternC(T) = SetFunctionAttributes!(T, "C", functionAttributes!T);

 auto assumePure(T)(T t)
     if (isFunctionPointer!T || isDelegate!T)
 {
     enum attrs = functionAttributes!T | FunctionAttribute.pure_;
     return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
 }

该示例添加了属性 pure,但类似的模式也可以删除属性。