Re: Scope guards

2023-06-26 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/26/23 2:42 PM, Cecil Ward wrote: == { size_t p = offset; ++p; scope(exit) { writeOutput( 0, p ); ++p … ++p; return; } == The correctness of its behaviour depends on what the value of p is when it calls writeOutput(), and the value of p is being changed. To be correct, the final value

Re: Scope guards

2023-06-26 Thread Cecil Ward via Digitalmars-d-learn
On Monday, 26 June 2023 at 17:41:16 UTC, Paul Backus wrote: On Saturday, 24 June 2023 at 17:00:36 UTC, Cecil Ward wrote: I would like to use scope guards but in the guard I need to get access to some local variables at the end of the routine. This doesn’t really seem to make sense as to how it

Re: Scope guards

2023-06-26 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 24 June 2023 at 17:00:36 UTC, Cecil Ward wrote: I would like to use scope guards but in the guard I need to get access to some local variables at the end of the routine. This doesn’t really seem to make sense as to how it would work, because their values depend on the exact point

Re: scope guards & debugger breakpoints?

2018-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/18 1:50 PM, Robert M. Münch wrote: On 2018-05-21 17:24:12 +, Steven Schveighoffer said: I'm not 100% sure but I expect: scope(failure)     someCode(); putting a breakpoint on someCode should work. When calling a function an then setting the breakpoint there, like in someCode()

Re: scope guards & debugger breakpoints?

2018-05-21 Thread Robert M. Münch via Digitalmars-d-learn
On 2018-05-21 17:24:12 +, Steven Schveighoffer said: I'm not 100% sure but I expect: scope(failure) someCode(); putting a breakpoint on someCode should work. When calling a function an then setting the breakpoint there, like in someCode() yes, that should work. I used code like th

Re: scope guards & debugger breakpoints?

2018-05-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/21/18 1:00 PM, Robert M. Münch wrote: If I use scope(failure) with code that should be run if an exception is thrown, how can I set a breakpoint for this code in the debugger? I'm not 100% sure but I expect: scope(failure) someCode(); putting a breakpoint on someCode should work. -

scope guards & debugger breakpoints?

2018-05-21 Thread Robert M. Münch via Digitalmars-d-learn
If I use scope(failure) with code that should be run if an exception is thrown, how can I set a breakpoint for this code in the debugger? -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Seb via Digitalmars-d-learn
Mike Parker via Digitalmars-d-learn wrote: > On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour > wrote: >> >> I'm curious whether scope guards add any cost over the >> naive way, eg: >> >> ``` >> void fun(){ >> ... >>

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Seb via Digitalmars-d-learn
On Thursday, 8 February 2018 at 10:44:37 UTC, Mike Parker wrote: On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour wrote: I'm curious whether scope guards add any cost over the naive way, eg: ``` void fun(){ ... scope(success) {bar;} ... } ``` vs: ``` void fun(){ ...

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Daniel Kozak via Digitalmars-d-learn
zer before each return > statement) in the case where no exception is thrown > > > On Thu, Feb 8, 2018 at 2:44 AM, Mike Parker via Digitalmars-d-learn > wrote: > > On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour wrote: > >> > >> I'

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Daniel Kozak via Digitalmars-d-learn
ia Digitalmars-d-learn >> wrote: >> > On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour wrote: >> >> >> >> I'm curious whether scope guards add any cost over the naive way, eg: >> >> >> >> ``` >> >> void fun(

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
February 2018 at 10:09:12 UTC, Timothee Cour wrote: >> >> I'm curious whether scope guards add any cost over the naive way, eg: >> >> ``` >> void fun(){ >> ... >> scope(success) {bar;} >> ... >> } >> ``` >> >> vs: &g

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour 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 r

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
at 2:09 AM, Timothee Cour 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){ &g

are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
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)