Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, April 2008
Template generalization for Qt classes


Message 1 in thread

Not to be too fussy or pedantic but it seems to me that some Qt
classes could benefit from being template-ized for generality.

For example, QPoint and QPointF are basically the same thing for
integers and floats.

We could (should?) have:

template<typename T>
class QPoint
{
public:
QPoint(const T& _x, const T& _y):x(_x), y(_y){};

}

With the usual operators +, -, +=, etc. all defined if necessary for
the major data types (int, short, float, double, etc.).

The same could be said for QRectangle, QLine, etc.

Any reason this is not done??

Just curious.

Eric

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> [...]
> We could (should?) have:
> [...]

Just think of QPoint as:
	typedef QPointTemplate<int> QPoint;
and QPointF:
	typedef QPointTemplate<qreal> QPointF;
In this context the template is an implementation detail.

Why "should" the implementation use templates?

I'm not certain why the implementation doesn't use templates, but here 
are some thoughts:
* What do Qt users/maintainers win by switching to templates?
* Templates may result in larger object files.
* QPoint and QPointF have different implementations for methods such as
operator*=(qreal) and would need distinct specialization.
* Template code is harder to maintain. I'm not certain it's a good idea 
to use templates for the sake of being generic if genericity is not 
needed in the case at hand.

-- 
 [ signature omitted ]