模板函数的模板参数

发布于 2024-10-08 11:10:54 字数 1127 浏览 0 评论 0原文

我刚刚发布了一个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())));
}

错误是:

"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.

上面的代码是从 207 开始的。但它似乎抱怨反向迭代器。我真的无法理解它。我无法直接访问 Sun 编译器,所以我想知道我是否做错了什么。

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

typedef std::reverse_iterator<iterator> reverse_iterator;

That's line 65 that the compiler indicates关于。我需要添加 T 作为参数吗?我无法弄清楚有问题的错误。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落在眉间の轻吻 2024-10-15 11:10:54

正如比较 C++ 标准库 libCstd 和 libstlport 中所述,Sun C++ 编译器附带“C++ 标准库”的两个实现:libCstd 和 libstlport。不幸的是,libCstd 不符合标准,但出于向后兼容性的原因它是默认值。除其他差异外,libCstd 版本的 std::reverse_iterator 模板使用多个模板参数。

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

另请参阅:

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:

余生一个溪 2024-10-15 11:10:54

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文