A
Adrian Hawryluk
Does anyone know if there is a way of specialising based on whether
there is a constructor or destructor defined (i.e. not the default
constructor/destructor that C++ creates)?
I would like to try and optimise a template class's initialisation to
not bother initialising its elements if the type contained has no
specified default constructor. The same holds for the destructor.
Of course, the compiler may be able to optimise this, but I'm not sure
how far an optimiser will go in this case.
For efficiency reasons, I do not state the type in the class, but
allocate enough space for the type and use an in-place new on
construction, with a corresponding call to each destructor on
destruction. However, if there are many elements, the initialisation /
deinitialisation of all of the elements would be a waste of time if
there was actually nothing done. Could an optimiser detect this and
skip initialisation altogether?
Thanks in advance,
Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under a Creative Commons /
\ Attribution-Share Alike 3.0 License /
\_______[http://creativecommons.org/licenses/by-sa/3.0/]______/
\/_______[blog:_http://adrians-musings.blogspot.com/]______\/
there is a constructor or destructor defined (i.e. not the default
constructor/destructor that C++ creates)?
I would like to try and optimise a template class's initialisation to
not bother initialising its elements if the type contained has no
specified default constructor. The same holds for the destructor.
Of course, the compiler may be able to optimise this, but I'm not sure
how far an optimiser will go in this case.
For efficiency reasons, I do not state the type in the class, but
allocate enough space for the type and use an in-place new on
construction, with a corresponding call to each destructor on
destruction. However, if there are many elements, the initialisation /
deinitialisation of all of the elements would be a waste of time if
there was actually nothing done. Could an optimiser detect this and
skip initialisation altogether?
Thanks in advance,
Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ My newsgroup writings are licensed under a Creative Commons /
\ Attribution-Share Alike 3.0 License /
\_______[http://creativecommons.org/licenses/by-sa/3.0/]______/
\/_______[blog:_http://adrians-musings.blogspot.com/]______\/