Re: fwd declaring STL containers
 
LR wrote:
Mark P wrote:
Is there any way to forward declare STL container classes such as 
list, set, map, etc.?  (My impression is that there isn't, since these 
are all defined in std.)
Failing that, consider the following snippet of code:
//////////
#include <list>
template <class Ty = int>
struct Foo
{
  typedef std::list<Ty> Type;
};
//////////
If this block of code were included in a translation unit that never 
made any further reference to Foo or Foo::Type, is it reasonable to 
assume that the compiled code would not be any larger?  (I understand 
this is an implementation issue, but your experience and intuition 
would be very helpful.)  FWIW, my testing on gcc indicates no difference.
Could you expand on this a little bit?
Have you tried to compare something like:
int main() {
    static Foo f;
}
and
int main() { }
My intuition tells me these will be different sizes.  I tried with two 
compilers, with the first, the object file size changed, but not the 
executable file size.  With the second, both files changed size.
Did you mean the executable file size?  Object file size?  Footprint in 
memory at runtime?
I looked at object file size and executable file size and saw no 
difference.  I don't know that your example is particularly relevant to 
my issue though.  I never instantiate my Foo object-- it's only used to 
emulate a templated typedef.
[If you're curious, I have a bunch of these wrapped typedefs for 
various STL container classes which I use to supply my own default 
allocator. This in turn simplifies the client syntax significantly.  
However, they're all stuck together in a single header file which 
includes many of the STL container headers, even though any particular 
user of the header may only need some of them.]
Now I'm curious.  How does this simplify client syntax?
Compare the following two declarations:
std::map<Key, Ty, std::less<Key>,
          myAlloc<std::pair<const Key,Ty> > >  myMap;
my_map<Key,Ty>::Type  myMap;
The issue is that the allocator parameter is the last among all 
parameters so to override the default it's necessary to specify all 
parameters.  Compound this with the particularly unwieldy value_type of 
the map, and it gets pretty ugly.
-Mark