问题
I just released a skiplist container library. And the Sun compiler complains about this:
template <class T, class R>
bool operator==(const IndexedSkipList<T,R> &left, const IndexedSkipList<T,R> &right)
{
return ((left.size() == right.size()) &&
(std::equal(left.begin(), left.end(), right.begin())));
}
The errors are:
"include/CSIndexedSkipList.h", line 65: Error: Too few arguments for template std::reverse_iterator<CS::BidiIdxIterator<CS::IndexedSkipList<CS::T, CS::R>>>.
"include/CSIndexedSkipList.h", line 207: Where: While specializing "CS::IndexedSkipList<CS::T, CS::R>".
"include/CSIndexedSkipList.h", line 207: Where: Specialized in non-template code.
The code above is what starts at 207. But it seems that it's complaining about the reverse_iterator. I can't really make sense of it. I don't have direct access to the Sun compiler, so I was wondering if I'm doing something wrong.
Also, I'm only using one template argument in reverse_iterator, but I noticed the SGI documentation saying that there is no default for the second argument T. Everywhere I've looked though, they just use this:
typedef std::reverse_iterator<iterator> reverse_iterator;
That's line 65 that the compiler complains about. Do I need to add T as a parameter? I can't figure out the error in question.
BTW, this works on gcc on all platforms I could find. And it works in Borland as well.
回答1:
As explained at Comparing C++ Standard Libraries libCstd and libstlport, the Sun C++ compiler ships with two implementations of a "C++ standard library": libCstd and libstlport. Unfortunately, libCstd is not standards-conforming, but it is the default for backward-compatibility reasons. Among other differences, libCstd's version of the std::reverse_iterator
template uses more than one template parameter.
You need to instruct the compiler to use libstlport by passing in the compiler option -library=stlport4
.
See also:
- Boost doesn't build on solaris when compiled with libCstd - focus on program_options
- Issue 53 - google-sparsehash - Compilation fails on SunOS CC compiler
回答2:
By the way, -library=stlport4
is NOT an option for performance-critical multithreaded applications running on Solaris because the version of STLPort
shipped with Sun Studio 12.1/12.2 is much slower than libCstd
due to spinlock mutexes on allocation/deallocation that are too slow on Solaris. STLPort5
should to be better in this regard, but I failed to build it on Solaris. It seems like STLPort
is no longer actively supported or used on Solaris, to say the least. So, we had to switch to libCstd
completely for all of our software, both on SPARC and on x86.
来源:https://stackoverflow.com/questions/4481379/template-arguments-to-template-functions