<div dir="ltr">Yes, it add, but is almost zero</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 8, 2018 at 12:00 PM, Timothee Cour via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I know that, my question is whether it adds any runtime overhead over<br>
naive way (which is to call the "bar" finalizer before each return<br>
statement)  in the case where no exception is thrown<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, Feb 8, 2018 at 2:44 AM, Mike Parker via Digitalmars-d-learn<br>
<<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@<wbr>puremagic.com</a>> wrote:<br>
> On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour wrote:<br>
>><br>
>> I'm curious whether scope guards add any cost over the naive way, eg:<br>
>><br>
>> ```<br>
>> void fun(){<br>
>>   ...<br>
>>   scope(success) {bar;}<br>
>>   ...<br>
>> }<br>
>> ```<br>
>><br>
>> vs:<br>
>><br>
>> ```<br>
>> void fun(){<br>
>>   ...<br>
>>   if(foo1){<br>
>>     bar;  // add this before each return<br>
>>     return;<br>
>>   }<br>
>>   ...<br>
>>   bar;<br>
>>   return;<br>
>> }<br>
>> ```<br>
>><br>
>> For scope(success) and scope(failure), the naive way would anyway<br>
>> involve try/catch statements but what about scope(exit)? Does the<br>
>> zero-cost exception model (zero cost being for non-thrown exceptions)<br>
>> guarantee us that scope(success) has 0 overhead over naive way?<br>
><br>
><br>
> Scope guards are lowered to the equivalent try/catch/finally blocks anyway.<br>
</div></div></blockquote></div><br></div>