comparison gcc/testsuite/g++.dg/cpp1z/constexpr-if27.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // PR c++/86969
2 // { dg-do compile { target c++17 } }
3
4 auto compose = [](auto... fs) {
5 if constexpr (sizeof...(fs) == 0) {
6 return [](auto x) { return x; };
7 } else {
8 auto fn = [](auto self, auto f, auto... fs) {
9 if constexpr (sizeof...(fs) == 0) return f;
10 else return [=](auto x) {
11 return f(self(self, fs...)(x));
12 };
13 };
14 return fn(fn, fs...);
15 }
16 };
17
18 static_assert(compose(
19 [](auto x) { return x * 3; },
20 [](auto x) { return x + 1; },
21 [](auto x) { return x / 2; }
22 )(6) == 12);