February 08, 2018 Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions? | ||||
---|---|---|---|---|
| ||||
likewise, will scope(exit) add any overhead over naive code in the
case where no exception is thrown?
```
void fun(){
...
scope(success) {bar;}
...
}
vs
void fun(){
...
if(foo1){
bar; // add this before each return
return;
}
...
bar;
return;
}
```
On Thu, Feb 8, 2018 at 2:09 AM, Timothee Cour <thelastmammoth@gmail.com> wrote:
> I'm curious whether scope guards add any cost over the naive way, eg:
>
> ```
> void fun(){
> ...
> scope(success) {bar;}
> ...
> }
> ```
>
> vs:
>
> ```
> void fun(){
> ...
> if(foo1){
> bar; // add this before each return
> return;
> }
> ...
> bar;
> return;
> }
> ```
>
> For scope(success) and scope(failure), the naive way would anyway
> involve try/catch statements but what about scope(exit)? Does the
> zero-cost exception model (zero cost being for non-thrown exceptions)
> guarantee us that scope(success) has 0 overhead over naive way?
|
Copyright © 1999-2021 by the D Language Foundation