| 1 |
// RUN: %clang_cc1 -std=c++2a -verify %s |
| 2 |
|
| 3 |
namespace std_example { |
| 4 |
namespace std { template<typename T> T &&move(T &); } |
| 5 |
|
| 6 |
void g(...); |
| 7 |
|
| 8 |
template <class... Args> void f(Args... args) { |
| 9 |
auto lm = [&, args...] { return g(args...); }; |
| 10 |
lm(); |
| 11 |
|
| 12 |
auto lm2 = [... xs = std::move(args)] { return g(xs...); }; |
| 13 |
lm2(); |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
template<typename ...T> constexpr int f(int k, T ...t) { |
| 18 |
auto a = [...v = t] (bool b) mutable { |
| 19 |
if (!b) { |
| 20 |
((v += 1), ...); |
| 21 |
return (__SIZE_TYPE__)0; |
| 22 |
} |
| 23 |
return (v * ... * 1) + sizeof...(v); |
| 24 |
}; |
| 25 |
for (int i = 0; i != k; ++i) |
| 26 |
a(false); |
| 27 |
return a(true); |
| 28 |
} |
| 29 |
|
| 30 |
static_assert(f(1, 2, 3, 4) == 3 * 4 * 5 + 3); |
| 31 |
static_assert(f(5) == 1); |
| 32 |
|
| 33 |
auto q = [...x = 0] {}; // expected-error {{does not contain any unexpanded parameter packs}} |
| 34 |
|
| 35 |
template<typename ...T> constexpr int nested(T ...t) { |
| 36 |
return [...a = t] { |
| 37 |
return [a...] { |
| 38 |
return (a + ...); |
| 39 |
}(); |
| 40 |
}(); |
| 41 |
} |
| 42 |
static_assert(nested(1, 2, 3) == 6); |