C++ (Qt)template <class T>class CModel { typedef T pointType; typedef std::vector<T> vectorType; vectorType *mCoord;};
C++ (Qt)template<class T>struct tester{ static bool is_same(const T&) { return true; } template <class U> static bool is_same(const U&) { return false; }};
C++ (Qt)int i;std::cout << tester<int>::is_same(i) << std::endl;std::cout << tester<long>::is_same(i) << std::endl; A *a = new A;std::cout << tester<A>::is_same(*a) << std::endl;std::cout << tester<B>::is_same(*a) << std::endl;
Bashtruefalse truefalse
C++ (Qt)template <class T1, class T2>void Append( T1 & dst. const T2 & src );
C++ (Qt)template<>void Append<vestor<PointD>, PointD>(vestor<PointD>& dst, const PointD &src);
C++ (Qt)class CModel { ... CoordVec * mCoord;};
C++ (Qt)template <class Point>void Append( vector<Point> & dst, const vector<Point> & src ) {...}
C++ (Qt)template <>void Append<PointF>( vector<PointF> & dst, const vector<PointF> & src ) {...}
C++ (Qt)void Append( CoordVec & dst, const CoordVec & src ){ switch (dst.Format()) { case format_3doub: switch (src.Format()) { case format_3doub: { CoordVecT <Point3D> & srcT = (CoordVecT <Point3D> &) src; CoordVecT <Point3D> & dstT = (CoordVecT <Point3D> &) dst; dst.mData.insert(...); break; } ... .... // и.т.д } .... // и.т.д } }
C++ (Qt)enum PointType {TypePointD, TypePointF, TypePointX, TypeUnknown}; template <class T>struct traits {static PointType type() { return TypeUnknown; }}; template<>struct traits<PointF>{static PointType type() { return TypePointF; }}; template<>struct traits<PointD>{static PointType type() { return TypePointD; }}; template<>struct traits<PointX>{static PointType type() { return TypePointX; }};
C++ (Qt)template <class Point>void Append(vector<Point>& dst, const vector<Point> & src){ PointType pt = traits<Point>::type(); switch (pt) { case TypePointF: {...} break; case TypePointD: {...} break; case TypePointX: {...} break; default: {...} }}
C++ (Qt)template <class Point>void Append(vector<Point>& dst, const vector<Point> & src){ PointType pt = traits<Point>::type(); switch (pt) { case PointF: {...} break; case PointD: {...} break; case PointX: {...} break; default: {...} }}
C++ (Qt)template <class T>class CModel {.. vector <T> mCoord;};
C++ (Qt)template <class T>void someMethod(CModel<T> &x) { x.someNonTemplateParametr = value; // ну и т.д.}