Boost logo

Boost :

From: Greer, Joe (jgreer_at_[hidden])
Date: 2007-08-10 14:58:12


I'm going to jump in here because I am interested in this question as
well.

>
> It's not the first time I've seen this, and I still do not understand
> what the belief of template meta-programming causing bloat is based
on.
>

I think the general impression is that if I write a template class like:

template<typename T, size_t N>
class something
{
   public:

      a bunch of methods using m_arr

   private:
      T m_arr[N];
}

Then the code may well be generated for each kind of T the class is
instantiated for and possible for each kind of N as well. Now, I don't
know if compiler technology can combine all the code instances
automatically or not. I do know that you can rewrite it with a base
class such that the implementation is typesafe for the user, but "a
bunch of methods" won't be duplicated (depending upon what they are
anyway). Maybe you know. Can the compiler recognize something like the
above and only create one copy of the code in the class?

joe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk