Reputation: 372
My question might be related to this one, but I think I don't have a "partially specialized non-type argument expression" here, or don't understand the relation.
The following code produce an internal error with MSVC14 compiler (CPP11):
template<typename T, T... Elmts>
struct NonTyped
{
};
template<typename T>
struct is_NonTyped_of_type
{
template<typename TL>
static constexpr bool check = false;
template<T... Elmts>
static constexpr bool check<NonTyped<T, Elmts...>> = true;
};
cout << is_NonTyped_of_type<int>::check<NonTyped<int, 5>> << endl;
Using only one non-type parameter instead of a non-type parameter pack would work as expected, but this fails.
Is this forbidden or undefined by the standard ? What rule does it break ?
Any workaround ?
Thank you very much!
Edit
The solution given by @StoryTeller did actually not work with MSVC14, but is very helpful to understand the problem we have here. Thanks a lot for your help, StoryTeller!
Upvotes: 1
Views: 209
Reputation: 170064
Clang accepts your code, while GCC did not. The partial specialization of your variable template should be okay as it is. You can always go back to the tried and tested way of using a regular class template to do the actual calculation.
template<typename T>
class is_NonTyped_of_type
{
template<typename TL>
struct check_impl : std::false_type {};
template<T... Elmts>
struct check_impl<NonTyped<T, Elmts...>> : std::true_type {};
public:
template<typename TL>
static constexpr bool check = check_impl<TL>::value;
};
Upvotes: 2