Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
profezzorn committed Dec 15, 2023
1 parent e3578f6 commit 7f9abda
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
42 changes: 24 additions & 18 deletions common/typelist.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef COMMON_TYPELIST_H
#define COMMON_TYPELIST_H

#include <type_traits>

template<typename ... T>
struct TypeList {
static const size_t size = sizeof...(T);
Expand All @@ -25,39 +27,43 @@ template<typename ... TL1, typename ... TL2, typename ... REST>
// Use this one
template<typename... REST> using ConcatTypeLists = typename::ConcatTypeListsHelper<REST...>::type;

// First
template<typename TL> struct FirstTypeListHelper { };
template<typename FIRST, typename ... REST>
struct FirstTypeListHelper<TypeList<FIRST, REST...>> { typedef FIRST type; };
template<typename TL> using FirstTypeList = typename FirstTypeListHelper<TL>::type;

// Rest
template<typename TL> struct RestTypeListHelper { };
template<typename FIRST, typename ... REST>
struct RestTypeListHelper<TypeList<FIRST, REST...>> { typedef TypeList<REST...> type; };
template<typename TL> using RestTypeList = typename RestTypeListHelper<TL>::type;



// Head
template<size_t n, typename TL> struct HeadTypeListHelper { };
template<typename ... TL>
struct HeadTypeListHelper<0, TypeList<TL...>> {
typedef TypeList<TL...> type;
template<size_t n, typename TL> struct HeadTypeListHelper {
typedef typename HeadTypeListHelper<n-1, RestTypeList<TL>>::type type;
};
template<size_t n, typename FIRST, typename ... TL>
struct HeadTypeListHelper<n, TypeList<FIRST, TL...>> {
typedef typename HeadTypeListHelper<n-1,TypeList<TL...>>::type type;
template<typename TL>
struct HeadTypeListHelper<0, TL> {
typedef TL type;
};

template<size_t n, typename TL> using HeadTypeList = typename::HeadTypeListHelper<n, TL>::type;

// Tail
template<size_t n, typename TL, typename prefix> struct TailTypeListHelper { };
template<size_t n, typename TL, typename prefix>
struct TailTypeListHelper {
typedef typename::TailTypeListHelper<n-1, RestTypeList<TL>, ConcatTypeLists<prefix, TypeList<FirstTypeList<TL>>>>::type type;
};
template<typename TL, typename prefix>
struct TailTypeListHelper<0, TL, prefix> {
typedef prefix type;
};
template<size_t n, typename FIRST, typename ... TL, typename ... prefix>
struct TailTypeListHelper<n, TypeList<FIRST, TL...>, TypeList<prefix...>> {
typedef typename TailTypeListHelper<n-1, TypeList<TL...>, TypeList<prefix..., FIRST> >::type type;
};

template<size_t n, typename TL> using TailTypeList = typename::TailTypeListHelper<n, TL, TypeList<>>::type;

// First
template<typename TL> struct FirstTypeListHelper { };
template<typename FIRST, typename ... REST>
struct FirstTypeListHelper<TypeList<FIRST, REST...>> { typedef FIRST type; };
template<typename TL> using FirstTypeList = typename FirstTypeListHelper<TL>::type;


template<typename TL>
struct SplitTypeList {
Expand Down
2 changes: 1 addition & 1 deletion styles/mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class MixHelper2<TypeList<A, B...>> {
private:
PONUA MixHelper2<typename SplitTypeList<TypeList<A, B...>>::first_half> a_;
PONUA MixHelper2<typename SplitTypeList<TypeList<A, B...>>::second_half> b_;
static int size() { return 1 + sizeof...(B); }
public:
static int size() { return 1 + sizeof...(B); }
auto getColor(int x, int led) -> decltype(MixColors(a_.getColor(0, led), b_.getColor(0, led), 1, 1)) {
if (x < a_.size()) return a_.getColor(x, led);
return b_.getColor(x - a_.size(), led);
Expand Down

0 comments on commit 7f9abda

Please sign in to comment.