// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025 - 2026  Medusa Slockbower
//
//  This program 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.
//
//  This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================

#ifndef FENNEC_CONTAINERS_DETAIL_TUPLE_H
#define FENNEC_CONTAINERS_DETAIL_TUPLE_H

#include <fennec/lang/metasequences.h>
#include <fennec/lang/utility.h>

namespace fennec::detail
{


template <size_t I, typename T>
struct _tuple_leaf
{
    constexpr _tuple_leaf(_tuple_leaf&&) noexcept = default;
    constexpr _tuple_leaf(const _tuple_leaf&) = default;

    template <typename ArgT> requires(not is_same_v<remove_cvref_t<ArgT>, _tuple_leaf>)
    constexpr explicit _tuple_leaf(ArgT&& arg) : value(fennec::forward<ArgT>(arg)) {}

    constexpr ~_tuple_leaf() = default;

    constexpr _tuple_leaf& operator=(const _tuple_leaf&) = default;
    constexpr _tuple_leaf& operator=(_tuple_leaf&&) noexcept = default;

    T value;
};

template <typename, typename...>
struct _tuple;

template <size_t...IndicesV, typename...TypesT>
struct _tuple<index_metasequence<IndicesV...>, TypesT...> : _tuple_leaf<IndicesV, TypesT>...
{
    constexpr _tuple(_tuple&&) noexcept = default;
    constexpr _tuple(const _tuple&) = default;

    template <typename...ArgsT>
    constexpr explicit _tuple(ArgsT&&... args)
        : _tuple_leaf<IndicesV, TypesT>(fennec::forward<ArgsT>(args))... {
    }

    constexpr _tuple& operator=(const _tuple&) = default;
    constexpr _tuple& operator=(_tuple&&) noexcept = default;

    constexpr ~_tuple() = default;
};

}

#endif // FENNEC_CONTAINERS_DETAIL_TUPLE_H
