December 20, 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@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.)
December 20, 2013
On 12/20/2013 10:57 PM, Timon Gehr wrote:
>
> 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.)

Actually, it seems that the behaviour of DMD has changed in this respect. It does not seem to be an issue any longer.
December 21, 2013
On Friday, 20 December 2013 at 20:42:13 UTC, monarch_dodra wrote:
> AFAIK, there is no real difference, but "is(typeof())" is more "idiomatic" in phobos.

Most uses of `is(typeof())` were written before the `compiles` trait was introduced. Add the cargo cult to that, and it's no wonder that Phobos uses `is(typeof())` so liberally, but I think the `compiles` trait shows intent better and benefits from fewer parentheses.

However, there is the problem that uses of `__traits` are supposed to be internal, not user-facing. We haven't made much headway on that one.
1 2
Next ›   Last »