annotate clang/test/SemaTemplate/temp-param-subst-linear.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -std=c++17 %s -verify
anatofuz
parents:
diff changeset
2 // expected-no-diagnostics
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 // This test attempts to ensure that the below template parameter pack
anatofuz
parents:
diff changeset
5 // splitting technique executes in linear time in the number of template
anatofuz
parents:
diff changeset
6 // parameters. The size of the list below is selected so as to execute
anatofuz
parents:
diff changeset
7 // relatively quickly on a "good" compiler and to time out otherwise.
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 template<typename...> struct TypeList;
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 namespace detail {
anatofuz
parents:
diff changeset
12 template<unsigned> using Unsigned = unsigned;
anatofuz
parents:
diff changeset
13 template<typename T, T ...N> using ListOfNUnsignedsImpl = TypeList<Unsigned<N>...>;
anatofuz
parents:
diff changeset
14 template<unsigned N> using ListOfNUnsigneds =
anatofuz
parents:
diff changeset
15 __make_integer_seq<ListOfNUnsignedsImpl, unsigned, N>;
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 template<typename T> struct TypeWrapper {
anatofuz
parents:
diff changeset
18 template<unsigned> using AsTemplate = T;
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 template<typename ...N> struct Splitter {
anatofuz
parents:
diff changeset
22 template<template<N> class ...L,
anatofuz
parents:
diff changeset
23 template<unsigned> class ...R> struct Split {
anatofuz
parents:
diff changeset
24 using Left = TypeList<L<0>...>;
anatofuz
parents:
diff changeset
25 using Right = TypeList<R<0>...>;
anatofuz
parents:
diff changeset
26 };
anatofuz
parents:
diff changeset
27 };
anatofuz
parents:
diff changeset
28 }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 template<typename TypeList, unsigned N, typename = detail::ListOfNUnsigneds<N>>
anatofuz
parents:
diff changeset
31 struct SplitAtIndex;
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 template<typename ...T, unsigned N, typename ...NUnsigneds>
anatofuz
parents:
diff changeset
34 struct SplitAtIndex<TypeList<T...>, N, TypeList<NUnsigneds...>> :
anatofuz
parents:
diff changeset
35 detail::Splitter<NUnsigneds...>::
anatofuz
parents:
diff changeset
36 template Split<detail::TypeWrapper<T>::template AsTemplate...> {};
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 template<typename T, int N> struct Rep : Rep<typename Rep<T, N-1>::type, 1> {};
anatofuz
parents:
diff changeset
39 template<typename ...T> struct Rep<TypeList<T...>, 1> { typedef TypeList<T..., T...> type; };
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 using Ints = Rep<TypeList<int>, 14>::type;
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 template<typename T> extern int Size;
anatofuz
parents:
diff changeset
44 template<typename ...T> constexpr int Size<TypeList<T...>> = sizeof...(T);
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 using Left = SplitAtIndex<Ints, Size<Ints> / 2>::Left;
anatofuz
parents:
diff changeset
47 using Right = SplitAtIndex<Ints, Size<Ints> / 2>::Right;
anatofuz
parents:
diff changeset
48 static_assert(Size<Left> == 8192);
anatofuz
parents:
diff changeset
49 static_assert(Size<Right> == 8192);
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 template<typename L, typename R> struct Concat;
anatofuz
parents:
diff changeset
52 template<typename ...L, typename ...R> struct Concat<TypeList<L...>, TypeList<R...>> {
anatofuz
parents:
diff changeset
53 using type = TypeList<L..., R...>;
anatofuz
parents:
diff changeset
54 };
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 using Ints = Concat<Left, Right>::type;