C++ guys hate static_if?

Artur Skawina art.08.09 at gmail.com
Thu Mar 14 12:38:55 PDT 2013


On 03/14/13 16:05, monarch_dodra wrote:
> On Thursday, 14 March 2013 at 11:04:59 UTC, Artur Skawina wrote:
>> On 03/14/13 10:26, Don wrote:
>>> On Saturday, 9 March 2013 at 03:50:29 UTC, Walter Bright wrote:
>>>> On 3/8/2013 5:19 PM, Brad Anderson wrote:
>>>>> On Saturday, 9 March 2013 at 00:48:59 UTC, DypthroposTheImposter wrote:
>>>>>>      Are they full of it? Has it caused the problems they mention
>>>>>> in
>>>>>> D?
>>>>>
>>>>> Well, the two guys with an alternative proposal (concepts-lite) seem to hate
>>>>> static if (along with a third guy).
>>>>>
>>>>> There seems to be a lot of strawman arguments in this paper.
>>>>
>>>> Many of the criticisms in the paper are addressed by our positive experience with static if in D.
>>>
>>> I think the hard-to-analyze argument is a good one.
>>>
>>> I've created an enhancement for some analysis we could do without too much work:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=9715
>>> (I think my bug report shows a bigger problem with static if, than is reported in the paper; the problems arise only when you have two static ifs in the same scope).
>>>
>>
>> The gain from such checks would be minimal. Eg "return x.toray;".
> 
> I've already found plenty of such bugs in phobos, and wouldn't be surprised if this was one of its bigger sources of bugs.
> 
> Sure, phobos is template and static "super heavy", given it is more or less the D-STL, but still.
> 
> If the compiler can statically determine that a template branch simply *can't* compile, then the code should be turned down.

"If'. Sure, it is sometimes able to do that, but often enough this is impossible
without actually instantiating the template. And often the error will be trivial
to fix (typo etc), so it doesn't really matter. What's left is just a small
fraction of all possible errors - catching them is good, but the gain isn't
really that large.

> Having to instantiate a template just to check to make sure it is semantically correct is a huge pain.

Yes, but see above. I'm not saying it shouldn't be done - only that it isn't
such a big deal as it is made out to be. For example I'd estimate that most
(ie >50%) of my mistakes wouldn't get caught, and I'm not that special. :)

artur


More information about the Digitalmars-d mailing list