HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Library/include/mamba/core/util_scope.hpp
#ifndef MAMBA_CORE_UTIL_SCOPE_HPP
#define MAMBA_CORE_UTIL_SCOPE_HPP

#include <stdexcept>

#include "mamba/core/output.hpp"

#include "spdlog/spdlog.h"

namespace mamba
{

    template <typename F>
    struct on_scope_exit
    {
        F func;

        explicit on_scope_exit(F&& f)
            : func(std::forward<F>(f))
        {
        }

        ~on_scope_exit()
        {
            try
            {
                func();
            }
            catch (const std::exception& ex)
            {
                LOG_ERROR << fmt::format("Scope exit error (catched and ignored): {}", ex.what());
            }
            catch (...)
            {
                LOG_ERROR << "Scope exit unknown error (catched and ignored)";
            }
        }

        // Deactivate copy & move until we implement moves
        on_scope_exit(const on_scope_exit&) = delete;
        on_scope_exit& operator=(const on_scope_exit&) = delete;
        on_scope_exit(on_scope_exit&&) = delete;
        on_scope_exit& operator=(on_scope_exit&&) = delete;
    };
}

#endif