Does ScopeGuard use really lead to better code?

前端 未结 8 1873
-上瘾入骨i
-上瘾入骨i 2020-12-04 15:36

I came across this article written by Andrei Alexandrescu and Petru Marginean many years ago, which presents and discusses a utility class called ScopeGuard for writing exce

8条回答
  •  再見小時候
    2020-12-04 16:26

    Yes.

    It was so important in C++ that even a special syntax for it in D:

    void somefunction() {
        writeln("function enter");
        // c++ has similar constructs but not in syntax level
        scope(exit) writeln("function exit");
    
        // do what ever you do, you never miss the function exit output
    }
    

提交回复
热议问题