Hello,
I've been looking at MSVC's STL implementation ever since watching
Stefan Lavavej's channel 9 videos to see how things work.
I was looking at <complex> and wondered why MSVC's complex base class
inherits from the second template paramenter? In other words, is
there a particular reason why they do this:
// forward declarations
template<class T> class complex;
template<> class complex<float>;
template<> class complex<double>;
template<> class complex<long double>;
// POS (plain old structures)
struct fcomplex { float _val[2]; };
struct dcomplex { double _val[2]; };
struct lcomplex { long double _val[2]; };
// base class for explicit specializations
// why do they inherit from the template argument ValBase?
template<class T, class ValBase> class complex_base : public ValBase {};
// explicit specializations
template<> class complex<float> : public complex_base<float,fcomplex> {};
instead of:
// forward declarations
template<class T> class complex;
template<> class complex<float>;
template<> class complex<double>;
template<> class complex<long double>;
// base class for explicit specializations
// doesn't use inheritance but also works
template<class T>
class complex_base {
public :
T _val[2];
};
// explicit specializations
template<> class complex<float> : public complex_base<float> {};
Is it just a matter of flexibility perhaps?
Thanks,
Steven
