| 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 |
} |