This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Forward declaring standard library classes
- From: Chris Jefferson <caj at cs dot york dot ac dot uk>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 18 Nov 2004 22:05:34 +0000
- Subject: Forward declaring standard library classes
With regards earlier emails, I am now attempting to optimise sort to be
more efficent when classes with an efficent swap are in use. Early
results are impressive :)
However, my problem now is that I need to have some class which I
specialise to decide when I should use the more efficent versions. My
early version looks something like:
template<typename _Tp>
struct _UseSwap
{ enum{_M_type = 0};};
template<typename _Tp>
struct _UseSwap<std::vector<_Tp> >
{enum{_M_type = 1};};
...etc.
However, I don't want to pull in <vector>, <list>, <deque>, <map>,
etc... so I forward declare these classes. However, the following
doesn't compile:
***
#include<functional>
namespace std
{
template<typename _Tp>
class allocator;
template<class _Key, class _Compare = less<_Key>,
class _Alloc = allocator<_Key> >
class set;
}
#include<set>
***
complaining that I have redefined the default parameter to _Compare. It
(unsuprisingly) doesn't work with my original version, where I also
forward declare less.
At the moment I'm getting around this by simply including every standard
container in stl_algo.h, but obviously this cannot continue. Any
suggestions?
Sorry for possibly very stupid C++ programming question...
Chris