CategoryName

Provides string representations of the category of a symbol, where such is not a fundamental primitive variable but a module, a function, a delegate, a class or a struct.

Accurate module detection only works on compilers 2.087 and later, due to missing support for __traits(isModule).

template CategoryName (
alias sym
) {
static if(isFunction!sym)
enum type;
static if(!(isFunction!sym))
static if(isDelegate!sym)
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(is(sym == class) || is(typeof(sym) == class))
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(!(is(sym == class) || is(typeof(sym) == class)))
static if(is(sym == struct) || is(typeof(sym) == struct))
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(!(is(sym == class) || is(typeof(sym) == class)))
static if(!(is(sym == struct) || is(typeof(sym) == struct)))
static if(is(sym == interface) || is(typeof(sym) == interface))
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(!(is(sym == class) || is(typeof(sym) == class)))
static if(!(is(sym == struct) || is(typeof(sym) == struct)))
static if(!(is(sym == interface) || is(typeof(sym) == interface)))
static if(is(sym == union) || is(typeof(sym) == union))
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(!(is(sym == class) || is(typeof(sym) == class)))
static if(!(is(sym == struct) || is(typeof(sym) == struct)))
static if(!(is(sym == interface) || is(typeof(sym) == interface)))
static if(!(is(sym == union) || is(typeof(sym) == union)))
static if(((__VERSION__ >= 2087L) && __traits(isModule, sym)) || ((__VERSION__ < 2087L) && __traits(compiles, )))
enum type;
static if(!(isFunction!sym))
static if(!(isDelegate!sym))
static if(!(is(sym == class) || is(typeof(sym) == class)))
static if(!(is(sym == struct) || is(typeof(sym) == struct)))
static if(!(is(sym == interface) || is(typeof(sym) == interface)))
static if(!(is(sym == union) || is(typeof(sym) == union)))
static if(!(((__VERSION__ >= 2087L) && __traits(isModule, sym)) || ((__VERSION__ < 2087L) && __traits(compiles, ))))
enum type;
}

Members

Imports

fullyQualifiedName (from std.traits)
public import std.traits : isDelegate, isFunction, fullyQualifiedName;
Undocumented in source.
isDelegate (from std.traits)
public import std.traits : isDelegate, isFunction, fullyQualifiedName;
Undocumented in source.
isFunction (from std.traits)
public import std.traits : isDelegate, isFunction, fullyQualifiedName;
Undocumented in source.

Manifest constants

fqn
enum fqn;

The fully qualified name for the symbol sym is an alias of.

name
enum name;

A short name for the symbol sym is an alias of.

Parameters

sym

Symbol to provide the strings for.

Examples

module foo;

void bar() {}

alias categoryName = CategoryName!bar;

assert(categoryName.type == "function");
assert(categoryName.name == "bar");
assert(categoryName.fqn == "foo.bar");
bool localSymbol;

void fn() {}

auto dg = () => localSymbol;

class C {}
C c;

struct S {}
S s;

interface I {}

union U
{
    int i;
    bool b;
}

U u;

alias Ffn = CategoryName!fn;
static assert(Ffn.type == "function");
static assert(Ffn.name == "fn");
// Can't test fqn from inside a unittest

alias Fdg = CategoryName!dg;
static assert(Fdg.type == "delegate");
static assert(Fdg.name == "dg");
// Ditto

alias Fc = CategoryName!c;
static assert(Fc.type == "class");
static assert(Fc.name == "c");
// Ditto

alias Fs = CategoryName!s;
static assert(Fs.type == "struct");
static assert(Fs.name == "s");

alias Fm = CategoryName!(lu.traits);
static assert(Fm.type == "module");
static assert(Fm.name == "traits");
static assert(Fm.fqn == "lu.traits");

alias Fi = CategoryName!I;
static assert(Fi.type == "interface");
static assert(Fi.name == "I");

alias Fu = CategoryName!u;
static assert(Fu.type == "union");
static assert(Fu.name == "u");