this question has answer here:
as pointed out ecatmur, question has answer here.
this question obviously not duplicate of trailing return type using decltype variadic template function. tries propose simpler solution address issue in thread. question whether solution correct according standard, because gcc , clang disagree on it. read question little more carefully, , realize that.
this question inspired this one. i'm trying come simpler solution ones provided, , end this:
#include <iostream> struct s { template <typename t> static t sum(t t){ return t; } template <typename t, typename ...u> static auto sum(t t, u... u) -> decltype(t + sum(u...)) { return t + sum(u...); } }; int main() { std::cout << s::sum(1, 1.5, 2) << '\n'; }
while solution works gcc, not solve problem @ on clang. so, i'm wondering 1 correct.
best workaround came is:
#include <iostream> struct s { template <typename t> static t sum(t t){ return t; } template <typename s, typename t> static auto sum(s s, t t) -> decltype(s + t) { return s + t; } template <typename s, typename t, typename ...u> static auto sum(s s, t t, u... u) -> decltype(s + t) { return s + sum(t, u...); } }; int main() { std::cout << s::sum(1, 1.5, 2) << '\n'; }
clang seems have problem resolving recursive function/method in decltype directive...
Comments
Post a Comment