<commit_before>/*
 * Scope Guard
 * Copyright (C) 2017  offa
 *
 * This file is part of Scope Guard.
 *
 * Scope Guard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scope Guard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Scope Guard.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <utility>
#include <type_traits>
#include <exception>

namespace sr
{

    template<class Deleter>
    class scope_success
    {
    public:

        template<class D,
            std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
            std::enable_if_t<(!std::is_lvalue_reference<D>::value)
                                && std::is_nothrow_constructible<Deleter, D>::value, int> = 0
            >
        explicit scope_success(D&& deleter) : m_deleter(std::move(deleter)),
                                            m_execute_on_destruction(true)
        {
        }

        template<class D,
            std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
            std::enable_if_t<std::is_lvalue_reference<D>::value, int> = 0
            >
        explicit scope_success(D&& deleter) try : m_deleter(deleter),
                                            m_execute_on_destruction(true)
        {
        }
        catch( ... )
        {
            throw;
        }

        scope_success(const scope_success&) = delete;

        template<class T = Deleter,
            std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0
            >
        scope_success(scope_success&& other) : m_deleter(std::move(other.m_deleter)),
                                        m_execute_on_destruction(other.m_execute_on_destruction),
                                        m_uncaught_on_creation(uncaught_exceptions())
        {
            other.release();
        }

        template<class T = Deleter,
            std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0
            >
        scope_success(scope_success&& other) : m_deleter(other.m_deleter),
                                        m_execute_on_destruction(other.m_execute_on_destruction)
        {
            other.release();
        }

        ~scope_success() noexcept(noexcept(std::declval<Deleter>()))
        {<commit_msg>Missing field initialization of uncaught exceptions added.<commit_after>/*
 * Scope Guard
 * Copyright (C) 2017  offa
 *
 * This file is part of Scope Guard.
 *
 * Scope Guard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scope Guard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Scope Guard.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <utility>
#include <type_traits>
#include <exception>

namespace sr
{

    template<class Deleter>
    class scope_success
    {
    public:

        template<class D,
            std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
            std::enable_if_t<(!std::is_lvalue_reference<D>::value)
                                && std::is_nothrow_constructible<Deleter, D>::value, int> = 0
            >
        explicit scope_success(D&& deleter) : m_deleter(std::move(deleter)),
                                            m_execute_on_destruction(true),
                                            m_uncaught_on_creation(uncaught_exceptions())
        {
        }

        template<class D,
            std::enable_if_t<std::is_constructible<Deleter, D>::value, int> = 0,
            std::enable_if_t<std::is_lvalue_reference<D>::value, int> = 0
            >
        explicit scope_success(D&& deleter) try : m_deleter(deleter),
                                            m_execute_on_destruction(true),
                                            m_uncaught_on_creation(uncaught_exceptions())
        {
        }
        catch( ... )
        {
            throw;
        }

        scope_success(const scope_success&) = delete;

        template<class T = Deleter,
            std::enable_if_t<std::is_nothrow_move_constructible<T>::value, int> = 0
            >
        scope_success(scope_success&& other) : m_deleter(std::move(other.m_deleter)),
                                        m_execute_on_destruction(other.m_execute_on_destruction),
                                        m_uncaught_on_creation(uncaught_exceptions())
        {
            other.release();
        }

        template<class T = Deleter,
            std::enable_if_t<!std::is_nothrow_move_constructible<T>::value, int> = 0
            >
        scope_success(scope_success&& other) : m_deleter(other.m_deleter),
                                        m_execute_on_destruction(other.m_execute_on_destruction),
                                        m_uncaught_on_creation(other.m_uncaught_on_creation)
        {
            other.release();
        }

        ~scope_success() noexcept(noexcept(std::declval<Deleter>()))
        {
{'fraction_non_alphanumeric': 0.09468980924557484, 'fraction_numerical': 0.003780718336483932, 'mean_word_length': 2.05672268907563, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3271650', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1620, 'n_words': 387}