[kde-edu]: Templates or not ?

Benoit Jacob jacob at math.jussieu.fr
Mon Nov 19 17:26:50 CET 2007


Hi Vladimir,

It depends. How many different possible template specializations will be 
used? If there are only two (2d and 3d) then you can have your templated 
code internal to your library, specialize it from inside your library, and 
thus still make a binary library.

The cases where it makes more sense to go templated are:
- when the number of possible instanciations is higher (e.g. in Eigen, the 
numbers of rows/columns can be 1,2,3,4,... or dynamic, and the base type 
can be 
int,float,double,complex<...>)
- when you want to expose a lot of functionality which might not be 
actually used, and you don't want the unused stuff to inflate the binary 
size (e.g. in Eigen, we'll happily code a lot of advanced things without 
having to ponder whether it's worth the binary size, as templated code 
only gets compiled when it's used).
- when you want to achieve stuff that can only be achieved by template 
techniques (e.g. the expression templates in Eigen2).

About your introspection system, I don't see why static data members would 
be incompatible with templates. I think there's no problem at all. Once 
it's compiled, templated code becomes just ordinary binary code!

Looking forward to talk to you in Paris,

Benoit

On Mon, 19 Nov 2007, Vladimir wrote:

> Hello All,
>
> I'm thinking (still only in theory) about implementing 3d support for
> StepCore. A very big part of the library is almost dimensional-independent: I
> just need to replace Vector2d by Vector3d and the obvious way to do it is to
> use templates. But AFAIK this makes my library header-only which increases
> compilation time and disallows sharing of the library. Moreover, in StepCore
> I'm using my own object introspection system which needs static data members
> and I do not know how to implement them in header-only library. Is it
> possible ? Probably someone has some other suggestions ?
>
> --
>      Best Regards,
>        Vladimir
> _______________________________________________
> kde-edu mailing list
> kde-edu at mail.kde.org
> https://mail.kde.org/mailman/listinfo/kde-edu
>


More information about the kde-edu mailing list