C++11 scope exit guard, a good idea?

前端 未结 10 817
囚心锁ツ
囚心锁ツ 2020-12-08 05:00

I\'ve written a small utility class for C++11 which I use as a scope guard for easier handling of exception safety and similar things.

Seems somewhat like a hack. Bu

10条回答
  •  孤城傲影
    2020-12-08 05:38

    But is it a good idea?

    Sure. A related topic is the RAII paradigm.

    Or are there potential problems I have missed?

    You don't handle exceptions.

    Is there already a similar solution (with C++0x features) in boost or similar?

    Alexandrescu came up with ScopeGuard a long time back. Both Boost and std::tr1 has a thing called scoped_ptr and shared_ptr (with a custom deleter) that allows you to accomplish just this.

提交回复
热议问题