Template constraints: opCmp and opUnary!"++"

Timon Gehr timon.gehr at gmx.ch
Fri Dec 20 13:57:58 PST 2013


On 12/20/2013 09:42 PM, monarch_dodra wrote:
> On Friday, 20 December 2013 at 17:48:03 UTC, Philippe Sigaud wrote:
>> On Fri, Dec 20, 2013 at 6:33 PM, Francesco Cattoglio
>> <francesco.cattoglio at gmail.com> wrote:
>>
>>> Is there any difference between "is(typeof(<somecode>))" and
>>> __traits(compiles, <somecode>)?
>>
>> I find the latter cleaner: its intent is more apparent. I use
>> is(typeof()) only for really testing for type existence.
>
> AFAIK, there is no real difference,  but "is(typeof())" is more
> "idiomatic" in phobos.

I used is(typeof(...)) as that was used in the original post, but I 
think it is actually better to use __traits(compiles,...). The 
difference is that typeof will not check if all referenced symbols are 
indeed accessible in the given scope. (Currently __traits(compiles, ...) 
won't either, but I assume this is a bug.)

Most non-trivial templates that use is(typeof(...)) in the constraint 
can be broken. (In the sense that it is possible to instantiate them 
even though their body does not compile.)


More information about the Digitalmars-d-learn mailing list