Re: [C++11] recursive late-specified return type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nathan Ridge <zeratul976@xxxxxxxxxxx> 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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux