1 // PR c++/85149 2 // { dg-do run } 3 // { dg-additional-options -std=c++17 } 4 5 template <typename T> struct is_void { static constexpr bool value = false; }; 6 template <> struct is_void<void> { static constexpr bool value = true; }; 7 8 template<typename S, typename T> 9 constexpr decltype(auto) pipeline(S source, T target) 10 { 11 return [=](auto... args) 12 { 13 if constexpr(false 14 && is_void<decltype(source(args...))>::value) 15 { 16 source(args...); 17 return target(); 18 } 19 else 20 { 21 return target(source(args...)); 22 } 23 }; 24 } 25 26 int main() { 27 int i = 10; 28 int j = 42; 29 auto p = pipeline([&]{ return j; }, 30 [=](int val){ return val * i; }); 31 if (p() != 420) 32 __builtin_abort(); 33 } 34