Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板函数的模板参数_C++_Templates_Stl - Fatal编程技术网

C++ 模板函数的模板参数

C++ 模板函数的模板参数,c++,templates,stl,C++,Templates,Stl,我刚刚发布了一个skiplist容器库。Sun编译器对此表示不满: template <class T, class R> bool operator==(const IndexedSkipList<T,R> &left, const IndexedSkipList<T,R> &right) { return ((left.size() == right.size()) && (std::equal(le

我刚刚发布了一个skiplist容器库。Sun编译器对此表示不满:

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())));
}
模板
布尔运算符==(常量IndexedSkipList&左,常量IndexedSkipList&右)
{
返回((left.size()==right.size())&&
(std::equal(left.begin(),left.end(),right.begin());
}
错误是:

"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.
“include/CSIndexedSkipList.h”,第65行:错误:模板std::reverse\u迭代器的参数太少。
“include/CSIndexedSkipList.h”,第207行:其中:专门化“CS::IndexedSkipList”时。
“include/CSIndexedSkipList.h”,第207行:其中:专门用于非模板代码。
上面的代码是从207开始的。但它似乎在抱怨反向迭代器。我真的搞不懂。我没有直接访问Sun编译器的权限,所以我想知道我是否做错了什么

另外,我在reverse_iterator中只使用了一个模板参数,但我注意到SGI文档中说第二个参数T没有默认值。在我看过的所有地方,他们都使用这个:

typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse\u迭代器reverse\u迭代器;
这就是编译器抱怨的第65行。我是否需要添加T作为参数?我想不出有问题的错误

顺便说一句,这在我能找到的所有平台上都适用于gcc。在Borland中也有工作。

< P>如上面所解释的,Sun C++编译器使用C++标准库的两种实现方式:LIbcSTD和LIbSTLPART。不幸的是,libCstd不符合标准,但出于向后兼容性的原因,它是默认的。除其他差异外,libCstd版本的
std::reverse_迭代器
模板使用了多个模板参数

您需要通过传入编译器选项
-library=stlport4
来指示编译器使用libstlport

另见:


顺便说一句,
-library=stlport4
不是在Solaris上运行的性能关键型多线程应用程序的选项,因为Sun Studio 12.1/12.2附带的
STLPort
版本比
libCstd
慢得多,因为在Solaris上分配/解除分配时的自旋锁互斥锁速度太慢
STLPort5
在这方面应该更好,但我未能在Solaris上构建它。至少可以说,
STLPort
似乎不再在Solaris上得到积极支持或使用。因此,我们必须在SPARC和x86上完全切换到
libCstd