I want to write a template class to calculate the size of tuple,but error occur when compiling.
template <typename... Types>
struct tuple_size_<tuple<Types...>>{
static constexpr size_t value = sizeof... (Types);
};
CodePudding user response:
This looks like a partial specialization without preceding primary template, which would look like template <typename> struct tuple_size_ {};
.
CodePudding user response:
The problem is that you're providing a partial template specialization but haven't declared the corresponding primary template. That is, there is no class template that you want to specialize in the first place. In other words, it doesn't make sense to specialize something(the class template in your case) that isn't there in the first place.
To solve this you need to provide a declaration for the primary class template:
//primary template
template<typename> struct tuple_size_;
//now you can partially specialize the above primary template
struct tuple_size_<tuple<Types...>>{
static constexpr size_t value = sizeof... (Types);
};