p9-0x.cpp revision a009b59fc2c550a229b9146aabda8e33fe3a7771
1// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
2
3// Metafunction to extract the Nth type from a set of types.
4template<unsigned N, typename ...Types> struct get_nth_type;
5
6template<unsigned N, typename Head, typename ...Tail>
7struct get_nth_type<N, Head, Tail...> : get_nth_type<N-1, Tail...> { };
8
9template<typename Head, typename ...Tail>
10struct get_nth_type<0, Head, Tail...> {
11  typedef Head type;
12};
13
14// Placeholder type  when get_nth_type fails.
15struct no_type {};
16
17template<unsigned N>
18struct get_nth_type<N> {
19  typedef no_type type;
20};
21
22template<typename ...Args>
23typename get_nth_type<0, Args...>::type first_arg(Args...);
24
25template<typename ...Args>
26typename get_nth_type<1, Args...>::type second_arg(Args...);
27
28// Test explicit specification of function template arguments.
29void test_explicit_spec_simple() {
30  int *ip1 = first_arg<int *>(0);
31  int *ip2 = first_arg<int *, float*>(0, 0);
32  float *fp1 = first_arg<float *, double*, int*>(0, 0, 0);
33}
34
35// Template argument deduction can extend the sequence of template
36// arguments corresponding to a template parameter pack, even when the
37// sequence contains explicitly specified template arguments.
38// FIXME: Actually test what this paragraph specifies.
39#if 0
40void test_explicit_spec_extension() {
41  int *ip1 = first_arg<int *>(0, 0);
42  int *ip2 = first_arg<int *, float*>(0, 0, 0, 0);
43  float *fp1 = first_arg<float *, double*, int*>(0, 0, 0);
44  int i1 = second_arg<float *>(0, 0, 0);
45}
46#endif
47
48