__traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 8 23:03:46 UTC 2018


On Mon, Jan 08, 2018 at 10:59:44PM +0000, aliak via Digitalmars-d-learn wrote:
[...]
> onlineapp.d(61): Error: template std.traits.TemplateOf does not match
> any template declaration. And I use it like this:
> 
> enum r1Sorted = __traits(isSame, TemplateOf!(R1), SortedRange);

This seems unnecessarily complicated.  What about this instead?

	enum r1Sorted = is(R1 : SortedRange!T, T...);

Basically, what that is-expression means is: "Is R1 a template of the
form `SortedRange!T` where T is some list of template arguments".

Generally, using __traits directly is usually not recommended unless
there's no other way to achieve what you want.


T

-- 
By understanding a machine-oriented language, the programmer will tend to use a much more efficient method; it is much closer to reality. -- D. Knuth


More information about the Digitalmars-d-learn mailing list