| 318 | // "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189". |
| 319 | |
| 320 | struct scope_exit { |
| 321 | explicit scope_exit(std::function<void(void)> &&f) |
| 322 | : exit_function(std::move(f)), execute_on_destruction{true} {} |
| 323 | |
| 324 | scope_exit(scope_exit &&rhs) |
| 325 | : exit_function(std::move(rhs.exit_function)), |
| 326 | execute_on_destruction{rhs.execute_on_destruction} { |
| 327 | rhs.release(); |
| 328 | } |
| 329 | |
| 330 | ~scope_exit() { |
| 331 | if (execute_on_destruction) { this->exit_function(); } |
| 332 | } |
| 333 | |
| 334 | void release() { this->execute_on_destruction = false; } |
| 335 | |
| 336 | private: |
| 337 | scope_exit(const scope_exit &) = delete; |
| 338 | void operator=(const scope_exit &) = delete; |
| 339 | scope_exit &operator=(scope_exit &&) = delete; |
| 340 | |
| 341 | std::function<void(void)> exit_function; |
| 342 | bool execute_on_destruction; |
| 343 | }; |
| 344 | |
| 345 | } // namespace detail |
| 346 |
no outgoing calls
no test coverage detected