[C++11] recursive late-specified return type
Miles Bader
miles@gnu.org
Mon Nov 7 09:21:00 GMT 2011
Nathan Ridge <zeratul976@hotmail.com> writes:
> Could someone please clarify whether the following code (from [1]),
> which GCC trunk rejects, is valid (i.e. the error is a bug) or invalid?
I can't answer this question, but it will compile if you use
std::common_type<>, from <type_traits> to calculate the return
type.... e.g.:
#include <type_traits>
...
template <class T, class... P>
auto sum(const T& t, const P&... p) -> typename common_type<T, P...>::type
{
return t + sum(p...);
}
I can imagine that the reason your version might not compile is
because you're trying to use the multi-parameter version of sum, in
"decltype (t + sum (p...))" before the multi-parameter version of sum
has been fully declared (as the decltype is part of that declaration);
I dunno whether the compiler is supposed to handle that or not...
-Miles
--
Corporation, n. An ingenious device for obtaining individual profit without
individual responsibility.
More information about the Gcc-help
mailing list