www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Traits mega template

reply monkyyy <crazymonkyyy gmail.com> writes:
would a single mega template lib of traits bullshit be more 
wildly more compile time and usable efficient then phoboes 
isBlahBlahBlah?
when a isBidirectionalRange || isRandomAccess range is called, it 
probaly has to either a) abstract out a isRange to memoize(adding 
more template nesting or b) redetect if its a range twice 
breaking memoization

Explain!T could contain all the infomation and then that tpye 
could a) print everything it detects b)add normal ctfe functions 
for common usecases

when you call a T.to!S, how much of std.traits gets called, 
processed in a big indirect mess? How many calls of isStruct is 
called before calling a "getStruct___" because if you call it on 
int it dies?

When ive implimented my traits I find isNullable and isRange need 
to detect each other because phoboes in its wisdom made nullable 
a very very strange range so onto the pile of complexity it goes; 
if it was imperative, short curiting of static if had 50/50 odds 
to remove it entirely preemptively

Suppose instead you call explain!T once for a single `to` 
function maybe you threw it out to a toImpl!(int,float) but all 
the matching was standard code with a bunch of static ifs instead 
of navigating the mess of headers

etc.

anyone tried that?
Aug 09
next sibling parent reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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?
 when a isBidirectionalRange || isRandomAccess range is called,
All of Phobos's traits should be transcoded to builtin __traits for performance reasons. Using templates to implement traits is an anti-pattern both in D and C++ as templates are too costly and design for this purpose. This is how C++ does it. The C++ standard makes this a requirement for compiler implementations. The reason is performance. Until D has type functions that is.
Aug 10
next sibling parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
 and design for this purpose.
Should be not designed for this purpose.
Aug 10
prev sibling parent reply monkyyy <crazymonkyyy gmail.com> writes:
On Sunday, 10 August 2025 at 16:20:49 UTC, Per Nordlöw wrote:
 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?
 when a isBidirectionalRange || isRandomAccess range is called,
All of Phobos's traits should be transcoded to builtin __traits for performance reasons. Using templates to implement traits is an anti-pattern both in D and C++ as templates are too costly and design for this purpose. This is how C++ does it. The C++ standard makes this a requirement for compiler implementations. The reason is performance. Until D has type functions that is.
Thats not always possible, header `if` resolve to an expression and there are questions that are iterative such as all the listing the members of a struct and finding some function inside matches
Aug 10
parent reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 10 August 2025 at 16:27:00 UTC, monkyyy wrote:
 Thats not always possible
Please give references to specific Phobos traits along with descriptions to back these claims.
  header `if` resolve to an expression and there are questions 
 that are iterative such as all the listing the members of a 
 struct and finding some function inside matches
I don't understand what you mean by this. Please explain further.
Aug 10
parent monkyyy <crazymonkyyy gmail.com> writes:
On Sunday, 10 August 2025 at 21:25:29 UTC, Per Nordlöw wrote:
  header `if` resolve to an expression and there are questions 
 that are iterative such as all the listing the members of a 
 struct and finding some function inside matches
I don't understand what you mean by this. Please explain further.
`void foo(...)() if(isSomething!T)` If isSomething isnt exactly a __trait, such as `isBidirectionalRangeWithLengthAlsoCopyAndAlsoIsV3` it may not be practual to have users always get it exactly right is it will be an abstraction of some sort. The compiler devs dont necessarily pick my suggestions for api instantly either
Aug 10
prev sibling next sibling parent monkyyy <crazymonkyyy gmail.com> writes:
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?
re: dconf std.traits complaints I still think this could improve things
Aug 19
prev sibling parent monkyyy <crazymonkyyy gmail.com> writes:
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; } ```
Aug 21