I've got a strange problem that I've spent way too long looking at myself, and would appreciante any guidence anyone can give me. I'm trying to send a priority_queue to a templated function, and my compilers are giving me all kinds of nastyness that I'm having trouble sifting through.
The function works fine for all basic container types that support the two functions I'm using (top() and pop()) and some that dont support it, that I've added some wrappers for. But anytime I try to send one of the STL comparison functions (as a sorting predicate), the compilers start spitting out all kinds of junk to me.
Here's a (much much stripped down) example that replicates the problem I'm coming acrossed
//Disable Visual Studio warning with STL containers that create
// debug names longer than 255 characters.
//That is, any STL item containing another STL item
//This makes the compile look a lot cleaner for vector<stringstream>
#ifdef WIN32
#pragma warning(disable:4786)
#endif
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <fstream>
#include <list>
#include <vector>
#include <queue>
using namespace std;
template<class T>
void printResults(T & container);
typedef priority_queue<string,list<string>,greater<string> > pqgType;
int main(int argc, char ** argv){
pqgType pqgResults;
pqgResults.push("test1");
pqgResults.push("test2");
pqgResults.push("test3");
printResults<pqgType>(pqgResults);
cout << endl;
return 0;
}
/*
print contents of container, one item at a time
*/
template<class T> inline
void printResults(T & container){
unsigned int lineSize = 61;
string tempStr;
while(!container.empty()){
tempStr = container.top();
cout << '\\' << tempStr;
container.pop();
}
}
And these are the errors that get spit to me:
MSVC
c:\program files\microsoft visual studio\vc98\include\algorithm(1264) : error
C2784: '_D __cdecl std::operator -(const class
std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &,const class
std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not deduce tem
plate
argument for 'const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &'
from 'class std::list<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >,class std::allocator<class
std::basic_string<char,struct std::
char_traits<char>,class std::allocator<char> > > >::iterator'
c:\program files\microsoft visual studio\vc98\include\algorithm(1261) :
see reference to function template instantiation 'void __cdecl std::_Push_heap_0
(class std::list<class std::basic_string<char,struct
std::char_traits<char>,class std::al
locator<char> >,class std::allocator<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > > >::iterator,class
std::list<class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,class
std::allocator<class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > > >::iterator,struct std::greater<class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
> >,int *,class std::basic
_string<char,struct std::char_traits<char>,class std::allocator<char> > *)'
being compiled
gcc (g plus plus)
/usr/lib/gcc/i386-redhat-
linux/4.0.0/../../../../include/c++/4.0.0/bits/stl_heap.h: In function âvoid
std::make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with
_RandomAccessIterator = std::_List_iterator<std::string>, _Compare =
std::greater<std::string>]â:
And there's much more where those two came from... I've done everything I can think of, including digging through the files mentioned (and how its _soo_ much fun looking through standard libraries...)
This was part of a project to further my own understanding of how templates work, just a little frustrating when they dont ;) Any help, or guidence, is appreciated!