Topic: Thinking about bloat...


Author: thegoat4@airmail.net (Bryant Brandon)
Date: 1997/11/12
Raw View
   While working with the new STL(new for me,) I noticed that my program
is really big!  I disassembled it and saw template instantiations all over
the place.  Now, there is nothing inherently wrong with this other than I
have to recompile all of the <iostream> templates for each file and code
duplication.  The first, recompilation, doesn't bug me too much as the
copies are stripped out by my linker.  The second is evil.  So, while
looking upon this, I had a wild idea, aliasing templates.
   For example, on a PPC Mac, an int and a long are the exact same thing.
What if there were some way to tell the compiler that little fact?  The
syntax that springs to mind for a vector would be

   #if __dest_os == __mac_os && __defined(__POWERPC__)

   template std::vector<int> = template std::vector<long>;

   #endif                                                      (1)

   It's clear, concise, and would think fairly easy to impliment.  To be
consistant with the traditional role of =, this is not reflexive.  The
above would mean "A vector of ints is a vector of longs."  Not "A vector
of ints is the same as a vector of longs."  The following:

   template std::vector<int> = template std::vector<long>;
   template std::vector<long> = template std::vector<int>;     (2)

would be the same as if the second line were omitted because defining a
template as itself would have no effect. ie,

   template std::vector<int> = template std::vector<int>;      (3)

wouldn't do anything.  Since vector<int> was defined as vector<long>, the
compiler sees (2) as

   template std::vector<long> = template std::vector<long>;    (4)

   There is no checking by the compiler to ensure the types are actually
compatable.

   This would be a nice way for the implimentors to substantially reduce
the size of templated class libraries such as the STL.
   So, my real question is why hasn't this been done?  Is it simply that
I'm the first to think of it, or has it been killed before because of some
evil detail that popped up somewhere?
   Just curious.
   Replies by mail in addition to posts are most appreciated, although not
mandatory.  Thanks in advance.

B.B.       --I am not a goat!
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]