Function alias template gives an error with GCC, but not with VS2015

52 views Asked by At

The next code snippet shows how to I simplify user code, making library slightly more complicated. In other words add some syntactic sugar.

 Channel const& joinMulticast(NetAdres  const &group) const;

 /// Auto-construct NetAdres.
 /// joinMulticast() can take any combination of args and passes them to NetAdres::NetAdres() constructor. No need to write many overloads
 template<typename... Y>
 auto joinMulticast(Y&&... y)
    -> decltype(joinMulticast(std::declval<Y>()...))
 {
    return joinMulticast(NetAdres(std::forward<Y>(y)...));
 }

VS2015 eats silently, but GCC cannot digest this code with fatal error:

template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum)
         -> decltype(joinMulticast(std::declval<Y>()...))
                                   ~~~~~~~~~~~~~~~^~
1

There are 1 answers

0
kyb On BEST ANSWER

Since in my case return type is always the same, simplify construction:

template<typename... Y>
Channel const& joinMulticast(Y&&... y)
{
  return joinMulticast(NetAdres(std::forward<Y>(y)...));
}