Re: fwd declaring STL containers
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.)
Not by you, but the library provider could.
The reason is that it is allowed for the STL containers to accept more
template parameters than the set defined by the standard. (The extra
template parameters then must have default values, in order to conform
to the standards requirements.)
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.
[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.]
If you use those structures exclusively as type-aliasses, and you never
create an instance of them, then their existence should have no impact
at all on the generated code.
The only impact that it should have is in the resources that the
compiler uses (time and memory).
Thanks,
Mark
Bart
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/