Call a function before function exits

前端 未结 5 843
抹茶落季
抹茶落季 2021-01-28 21:49

I will begin with an example. Suppose I need to guard a code with a function inside a mutex. There are two ways of implementing this.

#include 
#         


        
5条回答
  •  庸人自扰
    2021-01-28 22:30

    There is a proposal for a generic scope guard to be included in the next C++ standard, and I think it is accepted. You can find an implementation here, together with a link to the reference paper.

    In principle, it is similar to the classical ScopeGuard, but it also provides some special cases e.g. for C-like file APIs.

提交回复
热议问题