Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template arguments to template functions

Tags:

c++

templates

stl

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.

like image 707
Vorlath Avatar asked Dec 19 '10 02:12

Vorlath


1 Answers

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
like image 169
Daniel Trebbien Avatar answered Nov 14 '22 19:11

Daniel Trebbien