test.cpp(167) : error C2664: 'tuple<short,>::tuple(const tuple<short,> &)' : can not convert argument 1 from 'const tuple<char,>' to 'short'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
test.cpp(167) : see reference to function template instantiation 'tuple<float,short>::tuple<double,char>(const tuple<double,char> &)' being compiled
test.cpp(167) : see reference to function template instantiation 'tuple<float,short>::tuple<double,char>(const tuple<double,char> &)' being compiled
test.cpp(175) : see reference to function template instantiation 'tuple<long,float,short>::tuple<int,double,char>(const tuple<int,double,char> &)' being compiled
test.cpp(175) : see reference to function template instantiation 'tuple<long,float,short>::tuple<int,double,char>(const tuple<int,double,char> &)' being compiled
with Visual Studio 2013 and in:
c:\Users\achernyaev\Documents\test.cpp: In function 'int main()':
c:\Users\achernyaev\Documents\test.cpp:175:35: error: conversion from 'tuple<int,double, char>' to non-scalar type 'tuple<long int, float, short int>' requested tuple<long,float,short> tpl2 = tpl;
^
with MinGW's g++ 4.8.1
Question: Is this code really malformed or maybe this feature isn't supported good enough yet?
Best regards, Alexander.
解決
There are several mistake in the code: Here is a corrected one:
I believe deduction fails when trying to match the parameter pack Values up with the non-pack parameter Head of the tuple template, per C++11 §14.8.2.5 [temp.deduct.type]/10:
If the parameter-declaration corresponding to Pi is a function parameter pack, then the type of its declarator-id is compared with each remaining parameter type in the parameter-type-list of A. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack. During partial ordering (14.8.2.4), if Ai was originally a function parameter pack:
if P does not contain a function parameter type corresponding to Ai then Ai is ignored;
otherwise, if Pi is not a function parameter pack, template argument deduction fails.
In any case, you could simplify the class by making the empty tuple the base case for the recursion, and defining the whole shebang as: