Ad

Create an infinite list of alternating 1s and 0s, like so:

1:0:1:0:....
module Knot where

import Debug.Trace

onesAndZeroes :: Num a => [a]
onesAndZeroes =
  let x = 1 : y
      y = 0 : x
   in x

Write a metafunction whose result type reverses the template parameters of a std::tuple.

(Maybe, possibly, functional programming.)

// For convenience
template <typename, typename>
struct append;

template <typename ...Ts, typename ...Us>
struct append<std::tuple<Ts...>, std::tuple<Us...>> {
  using type = std::tuple<Ts..., Us...>;
};

template <typename>
struct reverse;

template <typename T, typename ...Ts>
struct reverse<std::tuple<T, Ts...>> {
    using type = typename append<
      typename reverse<std::tuple<Ts...>>::type,
      std::tuple<T>
    >::type;
};

template <>
struct reverse<std::tuple<>> {
  using type = std::tuple<>;
};

static_assert(
  std::is_same_v<
    reverse<std::tuple<int, short, char>>::type,
    std::tuple<char, short, int>
  >
);

static_assert(
  std::is_same_v<
    reverse<std::tuple<int&, short, char, void, int*>>::type,
    std::tuple<int*, void, char, short, int&>
  >
);