'Change the base class when 'partial specialization' of a class template
When tracking the 'is_same_v' in C++17, I found the code below:
/// is_same
template<typename, typename>
struct is_same
: public false_type { };
template<typename _Tp>
struct is_same<_Tp, _Tp>
: public true_type { };
It seems it's a partial specialization of class/struct template. I write some test code as below:
#include <iostream>
using namespace std;
template <typename T1, typename T2, int v>
class base
{
public:
int flag {v};
T1 a;
};
template <typename, typename>
class child : public base<bool, bool, 1>
{
};
template <typename T>
class child<T, T> : public base<bool, bool, 0>
{
};
int main()
{
child<int, int> a;
cout << a.flag << endl;
child<int, float> b;
cout << b.flag << endl;
return 0;
}
It output:
0
1
If it is 'partial specialization' indeed, then what confused me now is it changes it's parent class when doing specialization (one derived from base(bool,bool,1) and another from base(bool,bool,0)), and the compiler just allow it. Are there any rules in the standard about this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
