MeshLib C++ Docs
Loading...
Searching...
No Matches
MRFinally.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMacros.h"
4
5#include <utility>
6
10#define MR_FINALLY DETAIL_MR_FINALLY( ScopeGuard )
11
12#define DETAIL_MR_FINALLY( type_ ) \
13 auto MR_CONCAT( _mrScopeGuard, __COUNTER__ ) = ::MR::detail::MakeScopeGuard<::MR::detail::type_>{} ->* [&]() -> void
14
15namespace MR::detail
16{
17
18template <typename F>
20{
21 F func;
22
23public:
24 ScopeGuard( F&& func ) : func( std::move( func ) ) {}
25 ScopeGuard( const ScopeGuard& ) = delete;
26 ScopeGuard& operator=( const ScopeGuard& ) = delete;
27 ~ScopeGuard() { func(); }
28};
29
30template <template <typename> typename T>
32{
33 template <typename F>
34 T<F> operator->*( F&& func )
35 {
36 return T<F>( std::move( func ) );
37 }
38};
39
40}
~ScopeGuard()
Definition MRFinally.h:27
ScopeGuard(F &&func)
Definition MRFinally.h:24
ScopeGuard & operator=(const ScopeGuard &)=delete
ScopeGuard(const ScopeGuard &)=delete
for internal use: namespace detail is not bound to other languages
Definition MRFastInt.h:19
Definition MRFinally.h:32
T< F > operator->*(F &&func)
Definition MRFinally.h:34