Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pe_scope_guard/pe_scope_guard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef PE_SCOPE_GUARD_HPP
#define PE_SCOPE_GUARD_HPP

#include <concepts>
#include <tuple>
#include <type_traits>
#include <utility>

namespace peach
{

template< typename... Tys > class ScopeGuard
{
public:
constexpr ScopeGuard( Tys... callables ) requires( ( std::same_as< std::invoke_result_t< Tys >, void > && ... ) )
: m_callables( std::make_tuple( callables... ) )
{
}

~ScopeGuard( ) noexcept
{
std::apply( []( auto&&... args ) { ( ( args( ) ), ... ); }, m_callables );
}
Comment thread
joren-dev marked this conversation as resolved.

private:
std::tuple< Tys... > m_callables;
};

} // namespace peach

#endif // PE_SCOPE_GUARD_HPP