The evils of __traits(compiles)
Paul Backus
snarwin at gmail.com
Thu Jan 21 23:53:31 UTC 2021
On Thursday, 21 January 2021 at 22:09:46 UTC, jmh530 wrote:
> On Thursday, 21 January 2021 at 21:42:19 UTC, Paul Backus wrote:
>> [snip]
>>
>> This is also a great illustration of the pitfalls of using
>> __traits(compiles) without thorough unit testing, because your
>> code has a bug in it that isn't covered by your tests:
>>
>> static assert(isAddable!(inout(int))); // fails
>
> The code as it is used in the library requires isMutable!T
> before T gets passed into that logic.
>
> However, I still think it's weird. Changing inout to const or
> immutable works. I never would think to use inout(int) that
> way...
You probably wouldn't use inout that way directly, but you might
write something like
auto fun(T)(T a, T b)
if (isAddable!T)
{
// do something with a + b
}
...and then later on down the line you might call `fun` in some
context where T is inout-qualified, like a copy constructor.
More information about the Digitalmars-d
mailing list