1
我試圖實現以下(用C++ 17功能):爲什麼沒有采用非類型的部分特化元組?
#include <type_traits>
template<auto value_>
using constant_t = std::integral_constant<decltype(value_), value_>;
template<typename ... > class Tuple {};
template<auto ... values_>
class Tuple<constant_t<values_> ... > {};
int main(void)
{
Tuple<int, int, char> types;
Tuple<1, 2, 3> values;
}
這給了我下面的錯誤以g ++ - 7.1.0
main.cpp: In function ‘int main()’:
main.cpp:15:18: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ...> class Tuple’
Tuple<1, 2, 3> values;
^
main.cpp:15:18: note: expected a type, got ‘1’
main.cpp:15:18: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ...> class Tuple’
main.cpp:15:18: note: expected a type, got ‘2’
main.cpp:15:18: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ...> class Tuple’
main.cpp:15:18: note: expected a type, got ‘3’
任何人都可以解釋爲什麼部分Tuple<1, 2, 3>
專業化不啓動?
這就是我一直試圖避免(別名) –
但謝謝你,你有解釋爲什麼主模板不能改變接受值? –
@FletcherBlight - 專業化的本質。值不是一種更特殊的類型。它只是*有*類型。它有一個類型的事實不允許用它來代替它的類型。 – StoryTeller