Skip to content

Commit 02b90cf

Browse files
author
Julian LALU
committed
Fix compilation and simplifiy compressed tuple
1 parent 55385ad commit 02b90cf

File tree

2 files changed

+27
-68
lines changed

2 files changed

+27
-68
lines changed

interface/core/containers/compressed_tuple.h

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -256,52 +256,6 @@ namespace hud
256256
constexpr compressed_tuple_impl(compressed_tuple_impl &&) = default;
257257
};
258258

259-
/**
260-
* Recursively assign a compressed_tuple to another.
261-
* @tparam count Number of element to assign
262-
*/
263-
template<usize count>
264-
struct tuple_assign
265-
{
266-
/**
267-
* Assign a 2 compressed_tuple elements.
268-
* @tparam types_t... List of types_t of the compressed_tuple to
269-
* @tparam u_types_t... List of types_t of the compressed_tuple from
270-
* @param to The assigned compressed_tuple
271-
* @param from The compressed_tuple to assign
272-
*/
273-
template<typename... types_t, typename... u_types_t>
274-
constexpr void operator()([[maybe_unused]] hud::compressed_tuple<types_t...> &to, [[maybe_unused]] const hud::compressed_tuple<u_types_t...> &from) noexcept
275-
{
276-
static_assert(hud::tuple_size_v<hud::compressed_tuple<types_t...>> == hud::tuple_size_v<hud::compressed_tuple<u_types_t...>>, "Assigning tuples of different size is not supported");
277-
if constexpr (count > 0u)
278-
{
279-
constexpr const usize idx = tuple_size_v<hud::compressed_tuple<types_t...>> - count;
280-
hud::get<idx>(to) = hud::get<idx>(from);
281-
tuple_assign<count - 1u>()(to, from);
282-
}
283-
}
284-
285-
/**
286-
* Assign a 2 compressed_tuple elements.
287-
* @tparam types_t... List of types_t of the compressed_tuple to
288-
* @tparam u_types_t... List of types_t of the compressed_tuple from
289-
* @param to The assigned compressed_tuple
290-
* @param from The compressed_tuple to assign
291-
*/
292-
template<typename... types_t, typename... u_types_t>
293-
constexpr void operator()([[maybe_unused]] hud::compressed_tuple<types_t...> &to, [[maybe_unused]] hud::compressed_tuple<u_types_t...> &&from) noexcept
294-
{
295-
static_assert(hud::tuple_size_v<hud::compressed_tuple<types_t...>> == hud::tuple_size_v<hud::compressed_tuple<u_types_t...>>, "Assigning tuples of different size is not supported");
296-
if constexpr (count > 0)
297-
{
298-
constexpr const usize idx = tuple_size_v<hud::compressed_tuple<types_t...>> - count;
299-
hud::get<idx>(to) = hud::get<idx>(hud::move(from));
300-
tuple_assign<count - 1u>()(to, hud::move(from));
301-
}
302-
}
303-
};
304-
305259
/** Swap tuple1_t and tuple2_t element at the index if element is swappable. */
306260
template<usize type_index, typename tuple1_t, typename tuple2_t, bool = hud::is_swappable_v<hud::tuple_element_t<type_index, tuple1_t>, hud::tuple_element_t<type_index, tuple2_t>>>
307261
struct swap_element
@@ -752,7 +706,7 @@ namespace hud
752706
constexpr compressed_tuple &operator=(const compressed_tuple &other) noexcept
753707
requires(hud::conjunction_v<hud::is_copy_assignable<types_t>...>)
754708
{
755-
details::compressed_tuple::tuple_assign<sizeof...(types_t)>()(*this, other);
709+
details::tuple::tuple_assign<sizeof...(types_t), compressed_tuple, compressed_tuple>()(*this, other);
756710
return *this;
757711
}
758712

@@ -767,7 +721,7 @@ namespace hud
767721
requires(hud::conjunction_v<hud::is_copy_assignable<types_t, u_types_t>...>)
768722
constexpr compressed_tuple &operator=(const compressed_tuple<u_types_t...> &other) noexcept
769723
{
770-
details::compressed_tuple::tuple_assign<sizeof...(types_t)>()(*this, other);
724+
details::tuple::tuple_assign<sizeof...(types_t), compressed_tuple, compressed_tuple<u_types_t...>>()(*this, other);
771725
return *this;
772726
}
773727

@@ -781,7 +735,7 @@ namespace hud
781735
constexpr compressed_tuple &operator=(compressed_tuple &&other) noexcept
782736
requires(hud::conjunction_v<hud::is_move_assignable<types_t>...>)
783737
{
784-
details::compressed_tuple::tuple_assign<sizeof...(types_t)>()(*this, hud::move(other));
738+
details::tuple::tuple_assign<sizeof...(types_t), compressed_tuple, compressed_tuple>()(*this, hud::move(other));
785739
return *this;
786740
}
787741

@@ -796,7 +750,7 @@ namespace hud
796750
requires(hud::conjunction_v<hud::is_move_assignable<types_t, u_types_t>...>)
797751
constexpr compressed_tuple &operator=(compressed_tuple<u_types_t...> &&other) noexcept
798752
{
799-
details::compressed_tuple::tuple_assign<sizeof...(types_t)>()(*this, hud::move(other));
753+
details::tuple::tuple_assign<sizeof...(types_t), compressed_tuple, compressed_tuple<u_types_t...>>()(*this, hud::move(other));
800754
return *this;
801755
}
802756

@@ -897,7 +851,7 @@ namespace hud
897851
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, compressed_tuple<types_t...>> &get(compressed_tuple<types_t...> &t) noexcept
898852
{
899853
using type_t = tuple_element_t<idx_to_reach, compressed_tuple<types_t...>>;
900-
return static_cast<details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &>(t).element();
854+
return static_cast<typename details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &>(t).element();
901855
}
902856

903857
/**
@@ -911,7 +865,7 @@ namespace hud
911865
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, compressed_tuple<types_t...>> &get(const compressed_tuple<types_t...> &t) noexcept
912866
{
913867
using type_t = tuple_element_t<idx_to_reach, compressed_tuple<types_t...>>;
914-
return static_cast<const details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &>(t).element();
868+
return static_cast<const typename details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &>(t).element();
915869
}
916870

917871
/**
@@ -925,7 +879,7 @@ namespace hud
925879
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, compressed_tuple<types_t...>> &&get(compressed_tuple<types_t...> &&t) noexcept
926880
{
927881
using type_t = tuple_element_t<idx_to_reach, compressed_tuple<types_t...>>;
928-
return hud::forward<type_t>(static_cast<details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &&>(t).element());
882+
return hud::forward<type_t>(static_cast<typename details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &&>(t).element());
929883
}
930884

931885
/**
@@ -939,7 +893,7 @@ namespace hud
939893
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, compressed_tuple<types_t...>> &&get(const compressed_tuple<types_t...> &&t) noexcept
940894
{
941895
using type_t = tuple_element_t<idx_to_reach, compressed_tuple<types_t...>>;
942-
return hud::forward<const type_t>(static_cast<const details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &&>(t).element());
896+
return hud::forward<const type_t>(static_cast<const typename details::compressed_tuple::tuple_leaf_select<idx_to_reach, type_t>::type &&>(t).element());
943897
}
944898

945899
/**

interface/core/containers/tuple.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,14 @@ namespace hud
320320
* Recursively assign a tuple to another.
321321
* @tparam count Number of element to assign
322322
*/
323-
template<usize count>
324-
struct tuple_assign
323+
template<usize count, typename tuple_to_type, typename tuple_from_type>
324+
struct tuple_assign;
325+
326+
template<usize count, typename... types_t, typename... u_types_t>
327+
struct tuple_assign<count, hud::tuple<types_t...>, hud::tuple<u_types_t...>>
325328
{
329+
using tuple_to_type = hud::tuple<types_t...>;
330+
using tuple_from_type = hud::tuple<u_types_t...>;
326331

327332
/**
328333
* Assign a 2 tuple elements.
@@ -332,14 +337,14 @@ namespace hud
332337
* @param from The tuple to assign
333338
*/
334339
template<typename... types_t, typename... u_types_t>
335-
constexpr void operator()([[maybe_unused]] hud::tuple<types_t...> &to, [[maybe_unused]] const hud::tuple<u_types_t...> &from) noexcept
340+
constexpr void operator()([[maybe_unused]] tuple_to_type &to, [[maybe_unused]] const tuple_from_type &from) noexcept
336341
{
337-
static_assert(hud::tuple_size_v<hud::tuple<types_t...>> == hud::tuple_size_v<hud::tuple<u_types_t...>>, "Assigning tuples of different size is not supported");
342+
static_assert(hud::tuple_size_v<tuple_to_type> == hud::tuple_size_v<tuple_from_type>, "Assigning tuples of different size is not supported");
338343
if constexpr (count > 0u)
339344
{
340-
constexpr const usize idx = tuple_size_v<hud::tuple<types_t...>> - count;
345+
constexpr const usize idx = tuple_size_v<tuple_to_type> - count;
341346
hud::get<idx>(to) = hud::get<idx>(from);
342-
tuple_assign<count - 1u>()(to, from);
347+
tuple_assign<count - 1u, tuple_to_type, tuple_from_type>()(to, from);
343348
}
344349
}
345350

@@ -351,14 +356,14 @@ namespace hud
351356
* @param from The tuple to assign
352357
*/
353358
template<typename... types_t, typename... u_types_t>
354-
constexpr void operator()([[maybe_unused]] hud::tuple<types_t...> &to, [[maybe_unused]] hud::tuple<u_types_t...> &&from) noexcept
359+
constexpr void operator()([[maybe_unused]] tuple_to_type &to, [[maybe_unused]] tuple_from_type &&from) noexcept
355360
{
356-
static_assert(hud::tuple_size_v<hud::tuple<types_t...>> == hud::tuple_size_v<hud::tuple<u_types_t...>>, "Assigning tuples of different size is not supported");
361+
static_assert(hud::tuple_size_v<tuple_to_type> == hud::tuple_size_v<tuple_from_type>, "Assigning tuples of different size is not supported");
357362
if constexpr (count > 0)
358363
{
359-
constexpr const usize idx = tuple_size_v<hud::tuple<types_t...>> - count;
364+
constexpr const usize idx = tuple_size_v<tuple_to_type> - count;
360365
hud::get<idx>(to) = hud::get<idx>(hud::move(from));
361-
tuple_assign<count - 1u>()(to, hud::move(from));
366+
tuple_assign<count - 1u, tuple_to_type, tuple_from_type>()(to, hud::move(from));
362367
}
363368
}
364369
};
@@ -812,7 +817,7 @@ namespace hud
812817
constexpr tuple &operator=(const tuple &other) noexcept
813818
requires(hud::conjunction_v<hud::is_copy_assignable<types_t>...>)
814819
{
815-
details::tuple::tuple_assign<sizeof...(types_t)>()(*this, other);
820+
details::tuple::tuple_assign<sizeof...(types_t), tuple, tuple>()(*this, other);
816821
return *this;
817822
}
818823

@@ -827,7 +832,7 @@ namespace hud
827832
requires(hud::conjunction_v<hud::is_copy_assignable<types_t, u_types_t>...>)
828833
constexpr tuple &operator=(const tuple<u_types_t...> &other) noexcept
829834
{
830-
details::tuple::tuple_assign<sizeof...(types_t)>()(*this, other);
835+
details::tuple::tuple_assign<sizeof...(types_t), tuple, tuple<u_types_t...>>()(*this, other);
831836
return *this;
832837
}
833838

@@ -841,7 +846,7 @@ namespace hud
841846
constexpr tuple &operator=(tuple &&other) noexcept
842847
requires(hud::conjunction_v<hud::is_move_assignable<types_t>...>)
843848
{
844-
details::tuple::tuple_assign<sizeof...(types_t)>()(*this, hud::move(other));
849+
details::tuple::tuple_assign<sizeof...(types_t), tuple, tuple>()(*this, hud::move(other));
845850
return *this;
846851
}
847852

@@ -856,7 +861,7 @@ namespace hud
856861
requires(hud::conjunction_v<hud::is_move_assignable<types_t, u_types_t>...>)
857862
constexpr tuple &operator=(tuple<u_types_t...> &&other) noexcept
858863
{
859-
details::tuple::tuple_assign<sizeof...(types_t)>()(*this, hud::move(other));
864+
details::tuple::tuple_assign<sizeof...(types_t), tuple, tuple<u_types_t...>>()(*this, hud::move(other));
860865
return *this;
861866
}
862867

0 commit comments

Comments
 (0)