Mercurial > hg > CbC > CbC_gcc
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if17.C Thu Oct 25 07:37:49 2018 +0900 @@ -0,0 +1,32 @@ +// PR c++/85149 +// { dg-do run { target c++17 } } + +template <typename T> struct is_void { static constexpr bool value = false; }; +template <> struct is_void<void> { static constexpr bool value = true; }; + +template<typename S, typename T> +constexpr decltype(auto) pipeline(S source, T target) +{ + return [=](auto... args) + { + if constexpr(false + && is_void<decltype(source(args...))>::value) + { + source(args...); + return target(); + } + else + { + return target(source(args...)); + } + }; +} + +int main() { + int i = 10; + int j = 42; + auto p = pipeline([&]{ return j; }, + [=](int val){ return val * i; }); + if (p() != 420) + __builtin_abort(); +}