comparison gcc/testsuite/g++.dg/cpp1z/constexpr-if17.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 // PR c++/85149
2 // { dg-do run { target c++17 } }
3
4 template <typename T> struct is_void { static constexpr bool value = false; };
5 template <> struct is_void<void> { static constexpr bool value = true; };
6
7 template<typename S, typename T>
8 constexpr decltype(auto) pipeline(S source, T target)
9 {
10 return [=](auto... args)
11 {
12 if constexpr(false
13 && is_void<decltype(source(args...))>::value)
14 {
15 source(args...);
16 return target();
17 }
18 else
19 {
20 return target(source(args...));
21 }
22 };
23 }
24
25 int main() {
26 int i = 10;
27 int j = 42;
28 auto p = pipeline([&]{ return j; },
29 [=](int val){ return val * i; });
30 if (p() != 420)
31 __builtin_abort();
32 }