brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · fd93aa5 Raw
57 lines · cpp
1// RUN: %clang_cc1 -std=c++17 %s -verify2// expected-no-diagnostics3 4// This test attempts to ensure that the below template parameter pack5// splitting technique executes in linear time in the number of template6// parameters. The size of the list below is selected so as to execute7// relatively quickly on a "good" compiler and to time out otherwise.8 9template<typename...> struct TypeList;10 11namespace detail {12template<unsigned> using Unsigned = unsigned;13template<typename T, T ...N> using ListOfNUnsignedsImpl = TypeList<Unsigned<N>...>;14template<unsigned N> using ListOfNUnsigneds =15  __make_integer_seq<ListOfNUnsignedsImpl, unsigned, N>;16 17template<typename T> struct TypeWrapper {18  template<unsigned> using AsTemplate = T;19};20 21template<typename ...N> struct Splitter {22  template<template<N> class ...L,23           template<unsigned> class ...R> struct Split {24    using Left = TypeList<L<0>...>;25    using Right = TypeList<R<0>...>;26  };27};28}29 30template<typename TypeList, unsigned N, typename = detail::ListOfNUnsigneds<N>>31struct SplitAtIndex;32 33template<typename ...T, unsigned N, typename ...NUnsigneds>34struct SplitAtIndex<TypeList<T...>, N, TypeList<NUnsigneds...>> :35  detail::Splitter<NUnsigneds...>::36    template Split<detail::TypeWrapper<T>::template AsTemplate...> {};37 38template<typename T, int N> struct Rep : Rep<typename Rep<T, N-1>::type, 1> {};39template<typename ...T> struct Rep<TypeList<T...>, 1> { typedef TypeList<T..., T...> type; };40 41using Ints = Rep<TypeList<int>, 14>::type;42 43template<typename T> extern int Size;44template<typename ...T> constexpr int Size<TypeList<T...>> = sizeof...(T);45 46using Left = SplitAtIndex<Ints, Size<Ints> / 2>::Left;47using Right = SplitAtIndex<Ints, Size<Ints> / 2>::Right;48static_assert(Size<Left> == 8192);49static_assert(Size<Right> == 8192);50 51template<typename L, typename R> struct Concat;52template<typename ...L, typename ...R> struct Concat<TypeList<L...>, TypeList<R...>> {53  using type = TypeList<L..., R...>;54};55 56using Ints = Concat<Left, Right>::type;57