__traits so long and ugly, what about ::?

KennyTM~ kennytm at gmail.com
Wed Mar 30 20:13:24 PDT 2011


On Mar 31, 11 10:38, KennyTM~ wrote:
> On Mar 31, 11 09:42, Ary Manzana wrote:
>> I just hate it when you have to write too much to get simple things
>> done.
>>
>> Does this type have a member? Current approach:
>>
>> 1. import std.traits;
>> 2. invoke hasMember!(S, "m")
>>
>> Another approach:
>>
>> 1. I have the type, let's ask it: S::hasMember("m")
>>
>> Map's thought to code.
>>
>> My problem is that when you start using D's cool features you end up
>> with a really hard to understand and obscure code...
>
> How often do you really needs feature in __traits? I've grepped my code
> which uses a lot of templates and CTFE, and it only appears in 2 lines
>
> else static if (__traits(isScalar, T)) {
> static if (__traits(compiles, T.init.re))
>
> Therefore I oppose the use of :: just for __traits, because it's so rare.
>
> Now I have a counter-proposal,
>
> T::ident(x, y, z, ...) <=> ident!(T, x, y, z, ...)
>
> then hasMember can be invoked as
>
> import std.traits;
> ...
> S::hasMember("m")
>
> Isn't it better than reserving :: just for __traits?
>

PS. I don't mean to push this proposal. This is just to show that 
instead of using :: for __traits, there is a better alternative.


More information about the Digitalmars-d mailing list