Files
fennec/include/fennec/containers/tuple.h
2025-07-23 13:26:50 -04:00

65 lines
2.1 KiB
C++

// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 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_TUPLE_H
#define FENNEC_CONTAINERS_TUPLE_H
#include <fennec/containers/detail/__tuple.h>
#include <fennec/lang/type_sequences.h>
namespace fennec
{
// TODO: Document
template<typename...TypesT> struct tuple;
template<size_t i, typename...TypesT>
constexpr typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::__tuple_leaf<i, elem_t>>(x);
return it;
}
template<size_t i, typename...TypesT>
constexpr const typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::__tuple_leaf<i, elem_t>>(x);
return it;
}
template<typename...TypesT>
struct tuple : detail::__tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...> {
public:
using base_t = detail::__tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...>;
template<size_t i>
using elem_t = nth_element<i, TypesT...>;
template<typename...ArgsT>
constexpr tuple(ArgsT&&...args) : base_t(args...) {
}
};
}
#endif // FENNEC_CONTAINERS_TUPLE_H