Added fennec::allocation and all necessary dependencies
This commit is contained in:
@@ -52,23 +52,58 @@ template<bool_t B, typename T, typename F>
|
||||
struct conditional;
|
||||
|
||||
|
||||
///
|
||||
/// \brief Shorthand for ```typename conditional<ConditionV, TrueT, FalseT>::type```
|
||||
template<bool_t B, typename T, typename F>
|
||||
using conditional_t
|
||||
= typename conditional<B, T, F>::type;
|
||||
|
||||
|
||||
// specialization of fennec::conditional for \c true case
|
||||
// specialization of fennec::conditional for `true` case
|
||||
template<typename T, typename F>
|
||||
struct conditional<true, T, F>
|
||||
: type_transform<T>{};
|
||||
|
||||
|
||||
// specialization of fennec::conditional for \c false case
|
||||
// specialization of fennec::conditional for `false` case
|
||||
template<typename T, typename F>
|
||||
struct conditional<false, T, F>
|
||||
: type_transform<F>{};
|
||||
|
||||
|
||||
// fennec::detect ======================================================================================================
|
||||
|
||||
///
|
||||
/// \brief Detect whether `DetectT<ArgsT...>` is a valid type
|
||||
///
|
||||
/// \details The chosen type is stored in `detect::type` and
|
||||
/// a boolean value is stored in `detect::is_detected` representing whether `DetectT<ArgsT>`
|
||||
/// \tparam DefaultT Default type
|
||||
/// \tparam DetectT Type to detect
|
||||
/// \tparam ArgsT Any template arguments for `DetectT<ArgsT>`
|
||||
template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
|
||||
struct detect
|
||||
{
|
||||
using type = DefaultT;
|
||||
static constexpr bool is_detected = false;
|
||||
};
|
||||
|
||||
// true case
|
||||
template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
|
||||
requires requires { typename DetectT<ArgsT...>; }
|
||||
struct detect<DefaultT, DetectT, ArgsT...>
|
||||
{
|
||||
using type = DetectT<ArgsT...>;
|
||||
static constexpr bool is_detected = true;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// \brief Shorthand for ```typename detect<DefaultT, DetectT, ArgsT...>::type```
|
||||
template<typename DefaultT, template<typename...> typename DetectT, typename...ArgsT>
|
||||
using detect_t
|
||||
= typename detect<DefaultT, DetectT, ArgsT...>::type;
|
||||
|
||||
}
|
||||
|
||||
#endif //CONDITIONAL_TYPES_H
|
||||
|
||||
64
include/fennec/lang/detail/__numeric_transforms.h
Normal file
64
include/fennec/lang/detail/__numeric_transforms.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// =====================================================================================================================
|
||||
// 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_LANG_DETAIL_NUMERIC_TRANSFORMS_H
|
||||
#define FENNEC_LANG_DETAIL_NUMERIC_TRANSFORMS_H
|
||||
|
||||
#include <fennec/lang/types.h>
|
||||
#include <fennec/lang/type_transforms.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename> struct __make_unsigned : undefined_t {};
|
||||
|
||||
template<> struct __make_unsigned<char_t> : type_transform<uchar_t> {};
|
||||
template<> struct __make_unsigned<uchar_t> : type_transform<uchar_t> {};
|
||||
template<> struct __make_unsigned<schar_t> : type_transform<uchar_t> {};
|
||||
template<> struct __make_unsigned<short_t> : type_transform<ushort_t> {};
|
||||
template<> struct __make_unsigned<ushort_t> : type_transform<ushort_t> {};
|
||||
template<> struct __make_unsigned<uint_t> : type_transform<uint_t> {};
|
||||
template<> struct __make_unsigned<int_t> : type_transform<uint_t> {};
|
||||
template<> struct __make_unsigned<long_t> : type_transform<ulong_t> {};
|
||||
template<> struct __make_unsigned<ulong_t> : type_transform<ulong_t> {};
|
||||
template<> struct __make_unsigned<llong_t> : type_transform<ullong_t> {};
|
||||
template<> struct __make_unsigned<ullong_t> : type_transform<ullong_t> {};
|
||||
|
||||
|
||||
template<typename> struct __make_signed : undefined_t {};
|
||||
|
||||
template<> struct __make_signed<char_t> : type_transform<schar_t> {};
|
||||
template<> struct __make_signed<uchar_t> : type_transform<schar_t> {};
|
||||
template<> struct __make_signed<schar_t> : type_transform<schar_t> {};
|
||||
template<> struct __make_signed<short_t> : type_transform<short_t> {};
|
||||
template<> struct __make_signed<ushort_t> : type_transform<short_t> {};
|
||||
template<> struct __make_signed<uint_t> : type_transform<int_t> {};
|
||||
template<> struct __make_signed<int_t> : type_transform<int_t> {};
|
||||
template<> struct __make_signed<long_t> : type_transform<long_t> {};
|
||||
template<> struct __make_signed<ulong_t> : type_transform<long_t> {};
|
||||
template<> struct __make_signed<llong_t> : type_transform<llong_t> {};
|
||||
template<> struct __make_signed<ullong_t> : type_transform<llong_t> {};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_DETAIL_NUMERIC_TRANSFORMS_H
|
||||
@@ -28,36 +28,40 @@ namespace fennec
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename> struct __is_void_helper : false_type {};
|
||||
template<> struct __is_void_helper<void> : true_type {};
|
||||
// Nothing interesting to note here
|
||||
|
||||
template<typename> struct __is_bool_helper : false_type {};
|
||||
template<> struct __is_bool_helper<bool_t> : true_type {};
|
||||
template<typename> struct __is_void : false_type {};
|
||||
template<> struct __is_void<void> : true_type {};
|
||||
|
||||
template<typename> struct __is_integral_helper : false_type {};
|
||||
template<> struct __is_integral_helper<bool_t> : true_type {};
|
||||
template<> struct __is_integral_helper<char_t> : true_type {};
|
||||
template<> struct __is_integral_helper<char8_t> : true_type {};
|
||||
template<> struct __is_integral_helper<char16_t> : true_type {};
|
||||
template<> struct __is_integral_helper<char32_t> : true_type {};
|
||||
template<> struct __is_integral_helper<schar_t> : true_type {};
|
||||
template<> struct __is_integral_helper<uchar_t> : true_type {};
|
||||
template<> struct __is_integral_helper<wchar_t> : true_type {};
|
||||
template<> struct __is_integral_helper<short_t> : true_type {};
|
||||
template<> struct __is_integral_helper<ushort_t> : true_type {};
|
||||
template<> struct __is_integral_helper<int_t> : true_type {};
|
||||
template<> struct __is_integral_helper<uint_t> : true_type {};
|
||||
template<> struct __is_integral_helper<long_t> : true_type {};
|
||||
template<> struct __is_integral_helper<ulong_t> : true_type {};
|
||||
template<> struct __is_integral_helper<llong_t> : true_type {};
|
||||
template<> struct __is_integral_helper<ullong_t> : true_type {};
|
||||
template<typename> struct __is_bool : false_type {};
|
||||
template<> struct __is_bool<bool_t> : true_type {};
|
||||
|
||||
template<typename TypeT> struct __is_signed_helper : bool_constant<TypeT(-1) < TypeT(0)> {};
|
||||
template<typename TypeT> struct __is_unsigned_helper : bool_constant<TypeT(-1) >= TypeT(0)> {};
|
||||
// Provides definitions for all builtin int types
|
||||
template<typename> struct __is_integral : false_type {};
|
||||
template<> struct __is_integral<bool_t> : true_type {};
|
||||
template<> struct __is_integral<char_t> : true_type {};
|
||||
template<> struct __is_integral<char8_t> : true_type {};
|
||||
template<> struct __is_integral<char16_t> : true_type {};
|
||||
template<> struct __is_integral<char32_t> : true_type {};
|
||||
template<> struct __is_integral<schar_t> : true_type {};
|
||||
template<> struct __is_integral<uchar_t> : true_type {};
|
||||
template<> struct __is_integral<wchar_t> : true_type {};
|
||||
template<> struct __is_integral<short_t> : true_type {};
|
||||
template<> struct __is_integral<ushort_t> : true_type {};
|
||||
template<> struct __is_integral<int_t> : true_type {};
|
||||
template<> struct __is_integral<uint_t> : true_type {};
|
||||
template<> struct __is_integral<long_t> : true_type {};
|
||||
template<> struct __is_integral<ulong_t> : true_type {};
|
||||
template<> struct __is_integral<llong_t> : true_type {};
|
||||
template<> struct __is_integral<ullong_t> : true_type {};
|
||||
|
||||
template<typename> struct __is_floating_point_helper : false_type {};
|
||||
template<> struct __is_floating_point_helper<float_t> : true_type {};
|
||||
template<> struct __is_floating_point_helper<double_t> : true_type {};
|
||||
// Most unsigned types will underflow `-1` to the types maximum value
|
||||
template<typename TypeT> struct __is_signed : bool_constant<TypeT(-1) < TypeT(0)> {};
|
||||
template<typename TypeT> struct __is_unsigned : bool_constant<TypeT(-1) >= TypeT(0)> {};
|
||||
|
||||
template<typename> struct __is_floating_point : false_type {};
|
||||
template<> struct __is_floating_point<float_t> : true_type {};
|
||||
template<> struct __is_floating_point<double_t> : true_type {};
|
||||
|
||||
}
|
||||
|
||||
|
||||
36
include/fennec/lang/detail/__variadics.h
Normal file
36
include/fennec/lang/detail/__variadics.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// =====================================================================================================================
|
||||
// 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_LANG_DETAIL_VARIADICS_H
|
||||
#define FENNEC_LANG_DETAIL_VARIADICS_H
|
||||
|
||||
#include <fennec/lang/type_transforms.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename FirstT, typename... RestT> struct __first_element : type_transform<FirstT>{};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_DETAIL_VARIADICS_H
|
||||
@@ -20,11 +20,83 @@
|
||||
#ifndef FENNEC_LANG_INTRINSICS_H
|
||||
#define FENNEC_LANG_INTRINSICS_H
|
||||
|
||||
# if defined(__has_builtin)
|
||||
// Most major compilers support __has_builtin
|
||||
#if defined(__has_builtin)
|
||||
|
||||
|
||||
// bitcast is slightly more efficient for build times than using memcpy
|
||||
# define FENNEC_HAS_BUILTIN_BITCAST __has_builtin(__builtin_bit_cast)
|
||||
#if __has_builtin(__builtin_bit_cast)
|
||||
# define FENNEC_HAS_BUILTIN_BIT_CAST 1
|
||||
# define FENNEC_BUILTIN_BIT_CAST(type, arg) __builtin_bit_cast(type, arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_BIT_CAST 0
|
||||
#endif
|
||||
|
||||
# endif
|
||||
// addressof is very difficult to implement without intrinsics.
|
||||
#if __has_builtin(__builtin_addressof)
|
||||
# define FENNEC_HAS_BUILTIN_ADDRESSOF 1
|
||||
# define FENNEC_BUILTIN_ADDRESSOF(arg) __builtin_addressof(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_ADDRESSOF 0
|
||||
#endif
|
||||
|
||||
|
||||
// Type Traits
|
||||
|
||||
// can_convert is also very difficult to implement without intrinsics
|
||||
#if __has_builtin(__is_convertible)
|
||||
# define FENNEC_HAS_BUILTIN_CAN_CONVERT 1
|
||||
# define FENNEC_BUILTIN_CAN_CONVERT(arg0, arg1) __is_convertible(arg0, arg1)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_CAN_CONVERT 0
|
||||
#endif
|
||||
|
||||
// Inconsistent without intrinsics.
|
||||
#if __has_builtin(__is_empty)
|
||||
# define FENNEC_HAS_BUILTIN_IS_EMPTY 1
|
||||
# define FENNEC_BUILTIN_IS_EMPTY(arg) __is_empty(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_IS_EMPTY 0
|
||||
#endif
|
||||
|
||||
// Inconsistent without intrinsics
|
||||
#if __has_builtin(__is_polymorphic)
|
||||
# define FENNEC_HAS_BUILTIN_IS_POLYMORPHIC 1
|
||||
# define FENNEC_BUILTIN_IS_POLYMORPHIC(arg) __is_polymorphic(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_IS_POLYMORPHIC 0
|
||||
#endif
|
||||
|
||||
// Inconsistent without intrinsics
|
||||
#if __has_builtin(__is_final)
|
||||
# define FENNEC_HAS_BUILTIN_IS_FINAL 1
|
||||
# define FENNEC_BUILTIN_IS_FINAL(arg) __is_final(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_IS_FINAL 0
|
||||
#endif
|
||||
|
||||
// Inconsistent without intrinsics
|
||||
#if __has_builtin(__is_abstract)
|
||||
# define FENNEC_HAS_BUILTIN_IS_ABSTRACT 1
|
||||
# define FENNEC_BUILTIN_IS_ABSTRACT(arg) __is_abstract(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_IS_ABSTRACT 0
|
||||
#endif
|
||||
|
||||
// Impossible without instrinsics
|
||||
#if __has_builtin(__is_standard_layout)
|
||||
# define FENNEC_HAS_BUILTIN_IS_STANDARD_LAYOUT 1
|
||||
# define FENNEC_BUILTIN_IS_STANDARD_LAYOUT(arg) __is_standard_layout(arg)
|
||||
#else
|
||||
# define FENNEC_HAS_BUILTIN_IS_STANDARD_LAYOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
// For compilers without or differently named builtins
|
||||
#else
|
||||
|
||||
// TODO: More compiler support
|
||||
|
||||
#endif
|
||||
|
||||
#endif // FENNEC_LANG_INTRINSICS_H
|
||||
|
||||
@@ -39,6 +39,9 @@ enum float_round_style
|
||||
, round_toward_neg_infinity = 3
|
||||
};
|
||||
|
||||
///
|
||||
/// \brief Helper for getting traits of a numeric type
|
||||
/// \tparam TypeT Numeric types, may be overloaded for custom types
|
||||
template<typename TypeT> struct numeric_limits
|
||||
{
|
||||
static constexpr bool is_specialized = false;
|
||||
@@ -78,6 +81,7 @@ template<typename TypeT> struct numeric_limits
|
||||
static constexpr TypeT denorm_min() { return TypeT(); }
|
||||
};
|
||||
|
||||
// Overload for the builtin floating point type
|
||||
template<> struct numeric_limits<float>
|
||||
{
|
||||
static constexpr bool is_specialized = true;
|
||||
@@ -115,6 +119,7 @@ template<> struct numeric_limits<float>
|
||||
static constexpr double denorm_min() { return FLT_DENORM_MIN; }
|
||||
};
|
||||
|
||||
// Overload for the bultin double precision floating point type
|
||||
template<> struct numeric_limits<double>
|
||||
{
|
||||
static constexpr bool is_specialized = true;
|
||||
|
||||
46
include/fennec/lang/numeric_transforms.h
Normal file
46
include/fennec/lang/numeric_transforms.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// =====================================================================================================================
|
||||
// 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 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 License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file numeric_transforms.h
|
||||
/// \brief modify numeric types at compile time
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
|
||||
#ifndef FENNEC_LANG_NUMERIC_TRANSFORMS_H
|
||||
#define FENNEC_LANG_NUMERIC_TRANSFORMS_H
|
||||
|
||||
#include <fennec/lang/type_transforms.h>
|
||||
#include <fennec/lang/detail/__numeric_transforms.h>
|
||||
|
||||
// TODO: Document
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
template<typename TypeT> struct make_signed : detail::__make_signed<remove_cv_t<TypeT>> {};
|
||||
template<typename TypeT> struct make_unsigned : detail::__make_unsigned<remove_cv_t<TypeT>> {};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_NUMERIC_TRANSFORMS_H
|
||||
@@ -46,7 +46,7 @@ namespace fennec
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_void
|
||||
: detail::__is_void_helper<remove_cvr_t<T>>{};
|
||||
: detail::__is_void<remove_cvr_t<T>>{};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -66,7 +66,7 @@ template<typename T> constexpr bool_t is_void_v
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_bool
|
||||
: detail::__is_bool_helper<remove_cvr_t<T>>{};
|
||||
: detail::__is_bool<remove_cvr_t<T>>{};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -86,7 +86,7 @@ template<typename T> constexpr bool_t is_bool_v
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_integral
|
||||
: detail::__is_integral_helper<remove_cvr_t<T>> {};
|
||||
: detail::__is_integral<remove_cvr_t<T>> {};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -103,7 +103,7 @@ template<typename T> constexpr bool_t is_integral_v
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_signed
|
||||
: detail::__is_signed_helper<remove_cvr_t<T>> {};
|
||||
: detail::__is_signed<remove_cvr_t<T>> {};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -120,7 +120,7 @@ template<typename T> constexpr bool_t is_signed_v
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_unsigned
|
||||
: detail::__is_unsigned_helper<remove_cvr_t<T>> {};
|
||||
: detail::__is_unsigned<remove_cvr_t<T>> {};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -140,7 +140,7 @@ template<typename T> constexpr bool_t is_unsigned_v
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T> struct is_floating_point
|
||||
: detail::__is_floating_point_helper<remove_cvr_t<T>>{};
|
||||
: detail::__is_floating_point<remove_cvr_t<T>>{};
|
||||
|
||||
///
|
||||
///
|
||||
@@ -173,13 +173,14 @@ template<typename T> constexpr bool_t is_arithmetic_v
|
||||
|
||||
///
|
||||
///
|
||||
/// \brief check if
|
||||
/// \brief check if the two types are identical
|
||||
///
|
||||
/// \details
|
||||
/// \tparam T type to check
|
||||
template<typename T0, typename T1> struct is_same
|
||||
: false_type {};
|
||||
|
||||
// true case
|
||||
template<typename T> struct is_same<T, T>
|
||||
: true_type {};
|
||||
|
||||
@@ -190,6 +191,24 @@ template<typename T> struct is_same<T, T>
|
||||
template<typename T0, typename T1> constexpr bool_t is_same_v
|
||||
= is_same<T0, T1> {};
|
||||
|
||||
// fennec::can_convert =================================================================================================
|
||||
|
||||
///
|
||||
/// \brief check if type `T0` can be converted `T1`
|
||||
/// \tparam T0 First type
|
||||
/// \tparam T1 Second type
|
||||
template<typename T0, typename T1> struct can_convert
|
||||
: bool_constant<FENNEC_BUILTIN_CAN_CONVERT(T0, T1)> {};
|
||||
|
||||
///
|
||||
/// \brief shorthand
|
||||
/// \param T0 First type
|
||||
/// \param T1 Second type
|
||||
template<typename T0, typename T1> using can_convert_v = typename can_convert<T0, T1>::type;
|
||||
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_LANG_TYPE_TRAITS_H
|
||||
|
||||
@@ -197,6 +197,16 @@ using size_t = __SIZE_TYPE__;
|
||||
///
|
||||
/// \brief Signed Integer Type Returned by the Subtraction of two Pointers
|
||||
using ptrdiff_t = __PTRDIFF_TYPE__;
|
||||
|
||||
///
|
||||
/// \brief undefined class for SFINAE
|
||||
class undefined_t;
|
||||
|
||||
///
|
||||
/// \brief Void type used for SFINAE
|
||||
template<typename...>
|
||||
using void_t = void;
|
||||
|
||||
/// @}
|
||||
|
||||
}
|
||||
|
||||
66
include/fennec/lang/variadics.h
Normal file
66
include/fennec/lang/variadics.h
Normal file
@@ -0,0 +1,66 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file variadics.h
|
||||
/// \brief basic types of the c++ language
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_LANG_VARIADICS_H
|
||||
#define FENNEC_LANG_VARIADICS_H
|
||||
|
||||
#include <fennec/lang/detail/__variadics.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
///
|
||||
/// \brief Get the first element of a template parameter pack
|
||||
/// \tparam TypesT the Parameter Pack
|
||||
template<typename...TypesT> struct first_element : detail::__first_element<TypesT...> {};
|
||||
|
||||
///
|
||||
/// \brief alias for first_element<TypesT>::type
|
||||
template<typename...TypesT> using first_element_t = typename first_element<TypesT...>::type;
|
||||
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
/// \brief Take a Template with a Pack `ClassT<ArgsT...>` and replace the first `ArgT` of `ArgsT...` with `SubT`
|
||||
template<typename ClassT, typename SubT> struct replace_first_element { };
|
||||
|
||||
// Implementation
|
||||
template<
|
||||
template<typename, typename...> class ClassT // The Base Template
|
||||
, typename SubT, typename OriginT // The Original Type and Type to Substitute
|
||||
, typename... RestT> // The Rest of the Parameter Pack
|
||||
struct replace_first_element<ClassT<OriginT, RestT...>, SubT> // Specialization
|
||||
{ using type = ClassT<SubT, RestT...>; }; // Definition
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // FENNEC_LANG_VARIADICS_H
|
||||
Reference in New Issue
Block a user