मैं टेम्पलेट उपनाम में अनपॅकिंग वैरैडिक टेम्पलेट्स के साथ एक समस्या में भाग लेता हूं।टेम्पलेट उपनामों में पैरामीटर पैक अनपॅकिंग
निम्नलिखित कोड बजना 3.4 और जीसीसी 4.8 के साथ काम करता है, लेकिन जीसीसी 4.9 के साथ विफल:
template <typename T, typename...>
using front_type = T;
template <typename... Ts>
struct foo
{
using front = front_type<Ts...>;
};
जीसीसी 4.9 शिकायत:
test.cc:7:37: error: pack expansion argument for non-pack parameter 'T' of alias template 'template<class T, class ...> using front_type = T'
using front = front_type<Ts...>;
^
test.cc:1:15: note: declared here
template <typename T, typename...>
^
एक दायर जीसीसी बग (#59498) भी बना हुआ है, लेकिन है यह असफल होना चाहिए? यहाँ C++ core language issue #1430, "pack expansion into fixed alias template parameter list" से कुछ संदर्भ है:
Originally, a pack expansion could not expand into a fixed-length template parameter list, but this was changed in N2555. This works fine for most templates, but causes issues with alias templates.
In most cases, an alias template is transparent; when it's used in a template we can just substitute in the dependent template arguments. But this doesn't work if the template-id uses a pack expansion for non-variadic parameters. For example:
template<class T, class U, class V> struct S {}; template<class T, class V> using A = S<T, int, V>; template<class... Ts> void foo(A<Ts...>);
There is no way to express
A<Ts...>
in terms ofS
, so we need to hold onto theA
until we have theT
s to substitute in, and therefore it needs to be handled in mangling.Currently, EDG and Clang reject this testcase, complaining about too few template arguments for A. G++ did as well, but I thought that was a bug. However, on the ABI list John Spicer argued that it should be rejected.
क्या आप 'foo' के बाहर 'front_type' को स्थानांतरित कर सकते हैं - वे संबंधित नहीं हैं? – PiotrNycz
हाँ, अच्छा बिंदु @PiotrNycz। (हालांकि यह ठीक नहीं करता है।) – mavam
मैंने इस संशोधित कोड को gcc4.8 के साथ चेक किया - ऐसा लगता है कि यह काम करता है। – PiotrNycz