Traits mega template

monkyyy crazymonkyyy at gmail.com
Fri Aug 22 05:12:17 UTC 2025


On Saturday, 9 August 2025 at 17:16:21 UTC, monkyyy wrote:
> would a single mega template lib of traits bullshit be more 
> wildly more compile time and usable efficient then phoboes 
> isBlahBlahBlah?

example:

```d
--- meta.d

enum what{
	_struct,_union,_class,_interface,
	_enum,_function,_delegate,_module,
	_template,
	other
}
what whatis(alias T)(){
	static if(is(T==struct)){return what._struct;}
	static if(is(T==union)){return what._union;}
	static if(is(T==class)){return what._class;}
	static if(is(T==interface)){return what._interface;}
	static if(is(T==enum)){return what._enum;}
	static if(is(typeof(T)==function)){return what._function;}
	static if(is(T==delegate)){return what._delegate;}
	static if(is(T==module)){return what._module;}
	static if(__traits(isTemplate,T)){return what._template;}//what 
great api
	return what.other;
}
string[] members(alias T)(){
	enum what w=whatis!T;
	static if(w==what._function || w==what._delegate){
		static assert(0,"functions dont have memebers");
	}
	static if(w==what.other){
		static assert(0,"Im confused");
	}
	static if(w==what._template){
		static assert(0,"templates must be initualized");
	}
	return [__traits(allMembers,T)];
}
--- app.d
import meta;

enum foo{a,b};
void bar(){};
struct fizz{}
union fuzz{}
class buzz{}
auto foobar()(){}
struct fizzbuzz(){int i;}
unittest{
	import std;
	whatis!foo.writeln;
	whatis!bar.writeln;
	whatis!meta.writeln;
	//auto bar_=&bar;
	//whatis!(bar_).writeln;
	whatis!fizz.writeln;
	whatis!fuzz.writeln;
	whatis!buzz.writeln;
	whatis!foobar.writeln;
	whatis!fizzbuzz.writeln;
}
unittest{
	import std;
	members!foo.writeln;
	//members!bar.writeln; //"functions dont have memebers"
	members!meta.writeln;
	members!fizz.writeln;
	members!fuzz.writeln;
	members!buzz.writeln;
	//members!foobar.writeln;//"templates must be initualized"
	//members!(foobar!()).writeln;//"functions dont have memebers"
	//members!fizzbuzz.writeln;//"templates must be initualized"
	members!(fizzbuzz!()).writeln;
}
```




More information about the Digitalmars-d mailing list