2 // { dg-do compile { target c++11 } }
7 template < typename _Tp, _Tp > struct integral_constant
9 static constexpr _Tp value = 0;
10 typedef integral_constant type;
12 typedef integral_constant < int, 0 > true_type;
13 typedef integral_constant < int, 0 > false_type;
14 template < typename _Tp > struct enable_if
23 template < template < typename ... >class, typename ... >struct defer;
24 template < typename T > T * _nullptr_v ( );
25 template < int N > using size_t = std::integral_constant < int, N >;
26 template < int B > using bool_ = std::integral_constant < int, B >;
27 template < typename T > using dec =
28 std::integral_constant < decltype ( T::value ), 0 >;
29 template < typename T > using eval = typename T::type;
30 template < typename F, typename ... Args > using apply =
31 typename F::template apply < Args ... >;
34 template < typename > struct has_type_;
36 template < typename T > using has_type = eval < detail::has_type_ < T >>;
37 template < typename T > struct id
41 template < template < typename ... >class > struct quote;
42 template < typename > struct Trans_NS_extension_apply_list;
43 template < typename, typename List > using apply_list =
44 eval < Trans_NS_extension_apply_list < List >>;
47 template < typename ... >struct _if_;
48 template < typename If, typename Then > struct _if_ <If,
49 Then >:std::enable_if < Then >
53 template < typename ... Args > using if_ =
54 eval < detail::_if_ < Args ... >>;
55 template < int If, typename ... Args > using if_c =
56 eval < detail::_if_ < bool_ < If >, Args ... >>;
59 template < typename ... >struct _and_:std::true_type
62 template < typename ... >struct _or_:std::false_type
66 template < int >using not_c = bool_ < 0 >;
67 template < typename Bool > using not_ = not_c < Bool::value >;
68 template < typename ... >using and_ = eval < detail::_and_ <>>;
69 template < typename > using or_ = eval < detail::_or_ <>>;
72 template < typename ... Bools > using and_ = defer < and_, Bools ... >;
74 template < typename ... Ts > struct list
76 static constexpr std::size_t size ( )
78 return sizeof ... ( Ts );
81 template < typename List > using size = size_t < List::size ( ) >;
84 template < typename > struct concat_;
86 template < typename ... Lists > using concat =
87 eval < detail::concat_ < Lists ... >>;
88 template < typename ListOfLists > using join =
89 apply_list < quote < concat >, ListOfLists >;
92 template < int >struct repeat_n_c_
97 template < typename > using repeat_n = eval < detail::repeat_n_c_ < 0 >>;
98 template < std::size_t N > using repeat_n_c =
99 eval < detail::repeat_n_c_ < N >>;
102 template < typename > struct at_impl_
104 template < typename T > static T eval ( T * );
106 template < typename, typename > struct at_;
107 template < typename ... Ts, typename N > struct at_ <list < Ts ... >,
108 N >:decltype ( at_impl_ < repeat_n <
109 N >>::eval ( _nullptr_v < id < Ts >> ( )... ) )
113 template < typename List, typename N > using at =
114 eval < detail::at_ < List, N >>;
115 template < typename List, std::size_t > using at_c =
116 at < List, size_t < 0 >>;
119 template < typename > struct back_;
120 template < typename Head,
121 typename ... List > struct back_ <list < Head, List ... >>
123 using type = at_c < list < Head >, sizeof ... ( List ) >;
126 template < typename List > using back = eval < detail::back_ < List >>;
129 template < typename, typename > struct push_front_;
130 template < typename ... List,
131 typename T > struct push_front_ <list < List ... >, T >
133 using type = list < T >;
136 template < typename List, typename T > using push_front =
137 eval < detail::push_front_ < List, T >>;
140 template < typename > struct push_back_;
142 template < typename, typename T > using push_back =
143 eval < detail::push_back_ < T >>;
146 template < typename > struct transform_;
148 template < typename ... Args > using transform =
149 eval < detail::transform_ < Args ... >>;
152 template < typename > struct is_valid_;
153 template < typename As, typename Ts > using substitutions_ =
154 push_back < join < transform < concat < repeat_n_c < size < Ts >
157 >>>>, list < back < As >>>;
158 template < typename Ts > using substitutions =
159 apply < if_c < size < Ts >
162 , quote < substitutions_ >>>;
163 template < typename > struct is_vararg_:std::false_type
166 template < typename Tags > using is_variadic_ =
167 is_vararg_ < at < push_front < Tags, void >, dec < size < Tags >>>>;
168 template < typename Tags, int =
169 is_variadic_ < Tags >::value > struct lambda_;
170 template < typename ... As > struct lambda_ <list < As ... >, false >
172 using Tags = list < As ... >;
173 using F = back < Tags >;
174 template < typename, typename > struct impl;
175 template < typename, typename > struct subst_;
176 template < template < typename ... >class C, typename ... Ts,
177 typename Args > struct subst_ <defer < C, Ts ... >, Args >
179 using type = C < eval < impl < Ts, Args >> ... >;
181 template < template < typename ... >class C, typename ... Ts,
182 typename Args > struct impl <defer < C, Ts ... >,
183 Args >:subst_ < defer < C >, Args >
186 template < typename ... Ts > using apply =
187 eval < if_c < sizeof ... ( Ts ), impl < F, list <>>>>;
190 template < typename ... Ts > using lambda =
191 if_c < sizeof ... ( Ts ), detail::lambda_ < list < Ts ... >>>;
192 template < typename T > using is_valid = detail::is_valid_ < T >;
195 template < typename ... >struct let_;
196 template < typename Fn > struct let_ <Fn >
198 using type = apply < lambda < Fn >>;
201 template < typename ... As > using let = eval < detail::let_ < As ... >>;
202 template < typename > struct common_reference_base;
203 template < typename ... >struct common_reference;
206 template < typename > struct builtin_common_impl;
207 template < typename U > using builtin_common_t =
208 meta::apply < builtin_common_impl < U >>;
209 template < typename, typename > using lazy_builtin_common_t =
210 meta::defer < builtin_common_t >;
211 template < typename > struct transform_reference;
212 template < typename, typename U > using common_reference_base_ =
213 common_reference_base < meta::eval < transform_reference < U >>>;
215 template < typename T, typename U > struct common_reference <T,
216 U >:meta::if_ < meta::let < meta::lazy::and_ < meta::is_valid <
217 detail::lazy_builtin_common_t < T, U >>,
218 meta::or_ < meta::not_ < meta::has_type <
219 detail::common_reference_base_ < T, U >>>>>>,
220 detail::lazy_builtin_common_t < T, U >,
221 detail::common_reference_base_ < T, U >>