确定符号是否是模板函数

Met*_*eta 6 d template-meta-programming

我试图想出一种确定给定符号是否是函数模板的有效方法.下列:

import std.traits: isSomeFunction;

auto ref identity(T)(auto ref T t) { return t; }

static assert(isSomeFunction!identity);
Run Code Online (Sandbox Code Playgroud)

identity在实例化之前,仍然会失败,因为它仍然是模板.目前我正在使用一个依赖于<template function symbol>.stringof以某种方式格式化的事实的hack :

//ex: f.stringof == identity(T)(auto ref T t)
template isTemplateFunction(alias f)
{
    import std.algorithm: balancedParens, among;

    enum isTemplateFunction = __traits(isTemplate, f) 
        && f.stringof.balancedParens('(', ')') 
        && f.stringof.count('(') == 2 
        && f.stringof.count(')') == 2;
}

//Passes
static assert(isTemplateFunction!identity);
Run Code Online (Sandbox Code Playgroud)

我想知道除了hacky stringof解析之外是否有更好的方法来做到这一点.

Met*_*eta 0

看来现在在 D 中没有更好的方法来做到这一点,所以我将坚持解析 .stringof,尽管它是一个肮脏的黑客。