[Development] templates as QObjects

Olivier Goffart olivier at woboq.com
Tue Jun 26 23:17:03 CEST 2012


On Tuesday 26 June 2012 20:07:54 Peter Kümmel wrote:
> On 22.06.2012 09:26, Olivier Goffart wrote:
> > Nice stuff. Now you just need to make it for Qt5, and handle all the
> > special cases :-)
> > 
> > There is a room for tests in tets/auto/tools/moc (I'm saying that because
> > you made your test somewhere else)
> 
> OK, ported to Qt5 now:
> https://qt.gitorious.org/~syntheticpp/qt/qt5base/commit/3f37d08b81e63db6a844
> 4eff3c08afb044d72d67
> 
> Currently it uses "extradata" in QMetaObject where each concrete template
> instantiation stores its name (e.g. Foo<int> instead of Foo<T>).
> Is this pointer already used by someone else?
> Could we add another pointer to the private structure of QMetaObject even
> when this patch comes after 5.0, because when extradata is already used we
> later have no place for other new stuff.
> 
> I would like to use this patch as starting point for a merge request,
> so comments are welcome.
> 

I'm not sure the class name is that important.
I mean, if  Foo<int>().metaObject()->className() is just "Foo" it is still ok.
Because it is hard to support, and hardly usefull.

Also remember that template parametter can be more complex than just a type. 
It probably should support stuff as complicatd as this 

template <template<typename ... U> class T, 
          typename T<>::size_type = sizeof(T<>)> class Bar;
(I think i made that quite complicated already)

The fact that you have that macro Q_QOBJECT_TEMPLATE_USED limit you to only 
one parametter (because you cannot have coma in macro)
(But we could say it is ok to only support multple parametter with compiler 
that support variadic macros)


But to answer your question, the extraData is not being used currently and is 
reserved for future use, so yes, it can be used.

-- 
Olivier

Woboq - Qt services and support - http://woboq.com



More information about the Development mailing list