Skip to content

Instantly share code, notes, and snippets.

@Luiz-Monad
Created January 1, 2026 23:47
Show Gist options
  • Select an option

  • Save Luiz-Monad/e0de0b8dc8660684513c43723dd26337 to your computer and use it in GitHub Desktop.

Select an option

Save Luiz-Monad/e0de0b8dc8660684513c43723dd26337 to your computer and use it in GitHub Desktop.
template chaining
template <typename... Ts>
struct box {
using t = box<Ts...>;
};
template <typename... Ts>
struct flatten;
template <typename T>
struct flatten<T> {
using t = box<T>;
};
template <typename... Ts>
struct flatten<box<Ts...>> {
using t = box<Ts...>;
};
template <typename... Ls, typename... Rs>
struct flatten<box<Ls...>, box<Rs...>> {
using t = box<Ls..., Rs...>;
};
template <typename... Ls, typename R>
struct flatten<box<Ls...>, R> {
using t = box<Ls..., R>;
};
template <typename L, typename... Rs>
struct flatten<L, box<Rs...>> {
using t = box<L, Rs...>;
};
template <typename L, typename R>
struct flatten<L, R> {
using t = box<L, R>;
};
template <typename T>
struct unwrap {
using t = T;
};
template <typename... Ts>
struct unwrap<box<Ts...>> {
using t = box<Ts...>;
};
template <typename L, typename R>
struct chain {
using t = flatten<
typename unwrap<L>::t,
typename unwrap<R>::t
>::t;
};
template <template<typename...> class Clas, typename... Ts>
struct apply {
using t = Clas<Ts...>;
};
template <template<typename...> class Clas, typename... Ts>
struct apply<Clas, box<Ts...>> {
using t = Clas<Ts...>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment