Looking into some code of a colleague of mine, I came accross the following:
看一下我的同事的一些代码,我得到了以下内容:
friend bool operator==<>(ValueIter<Type> const &rhs, ValueIter<Type> const &lhs);
It is declared in a template class:
它在模板类中声明:
template<typename Type>
class ValueIter: public std::iterator<std::bidirectional_iterator_tag, Type>
Can someone tell me what the ==<>
symbol indicates? I expect it has something to with the !=
operator.
有人能告诉我== <>符号表示什么?我希望它与!=运算符有关。
3 个解决方案
#1
32
It looks like two, the operator==
that is a full template instantiation or specialisation <>
.
它看起来像两个,operator ==是一个完整的模板实例化或专门化<>。
I've seen only a few like this in the wild though.
我在野外只看到过这样的一些。
Given the friend
, the class is probably befriending the template operator.
鉴于朋友,该类可能与模板操作员保持联系。
If you are getting linker errors with it, see this answer for why.
如果您遇到链接器错误,请参阅此答案以了解原因。
#2
6
Your question is incomplete.
你的问题不完整。
Presumably, in some context within the code you are examining, there is a templated operator==()
function.
据推测,在您正在检查的代码中的某些上下文中,有一个模板化的运算符==()函数。
Then within some class, a particular specialisation of that templated operator==()
is being declared as a friend
.
然后在某个类中,该模板化运算符==()的特定特化被声明为朋友。
Without context that you haven't given (i.e. of the preceding template definition, or of the enclosing class definition) it is not possible to give a more specific answer. There are too many possibilities for what the template or relevant specialisations are.
如果没有您没有给出的上下文(即前面的模板定义或封闭类定义),则无法给出更具体的答案。模板或相关专业化的可能性太多了。
#3
5
With
template <typename T> class ValueIter;
template <typename T>
bool operator==(ValueIter<T> const &rhs, ValueIter<T> const &lhs);
Inside template <typename T> class ValueIter
内部模板
-
friend bool operator==(ValueIter const &rhs, ValueIter const &lhs);
andfriend bool operator==(ValueIter<T> const &rhs, ValueIter<T> const &lhs);
add friendship to a non template operator.friend bool operator ==(ValueIter const&rhs,ValueIter const&lhs);和朋友bool operator ==(ValueIter
const&rhs,ValueIter const&lhs);将友谊添加到非模板运算符。 -
friend bool operator==<>(ValueIter const &rhs, ValueIter const &lhs);
,friend bool operator==<>(ValueIter<T> const &rhs, ValueIter<T> const
friend bool operator==<T>(ValueIter const &rhs, ValueIter const &lhs);
,friend bool operator==<T>(ValueIter<T> const &rhs, ValueIter<T> const
add friendship to the template operator (just for the type with matchT
)friend bool operator == <>(ValueIter const&rhs,ValueIter const&lhs);, friend bool operator == <>(ValueIter
const&rhs,ValueIter const friend bool operator == (ValueIter const&rhs ,ValueIter const&lhs);, friend bool operator == (ValueIter const&rhs,ValueIter const为模板运算符添加友谊(仅适用于匹配T的类型) -
template <typename U> friend bool operator==(ValueIter<U> const &rhs, ValueIter<U> const &lhs);
add friendship to the template operator (for any typeU
(which may differ ofT
))template
friend bool operator ==(ValueIter const&rhs,ValueIter const&lhs);将友谊添加到模板运算符(对于任何类型U(可能不同于T))
==<>
is used in the second point and is really == <>
.
== <>用于第二点,实际上是== <>。
#1
32
It looks like two, the operator==
that is a full template instantiation or specialisation <>
.
它看起来像两个,operator ==是一个完整的模板实例化或专门化<>。
I've seen only a few like this in the wild though.
我在野外只看到过这样的一些。
Given the friend
, the class is probably befriending the template operator.
鉴于朋友,该类可能与模板操作员保持联系。
If you are getting linker errors with it, see this answer for why.
如果您遇到链接器错误,请参阅此答案以了解原因。
#2
6
Your question is incomplete.
你的问题不完整。
Presumably, in some context within the code you are examining, there is a templated operator==()
function.
据推测,在您正在检查的代码中的某些上下文中,有一个模板化的运算符==()函数。
Then within some class, a particular specialisation of that templated operator==()
is being declared as a friend
.
然后在某个类中,该模板化运算符==()的特定特化被声明为朋友。
Without context that you haven't given (i.e. of the preceding template definition, or of the enclosing class definition) it is not possible to give a more specific answer. There are too many possibilities for what the template or relevant specialisations are.
如果没有您没有给出的上下文(即前面的模板定义或封闭类定义),则无法给出更具体的答案。模板或相关专业化的可能性太多了。
#3
5
With
template <typename T> class ValueIter;
template <typename T>
bool operator==(ValueIter<T> const &rhs, ValueIter<T> const &lhs);
Inside template <typename T> class ValueIter
内部模板
-
friend bool operator==(ValueIter const &rhs, ValueIter const &lhs);
andfriend bool operator==(ValueIter<T> const &rhs, ValueIter<T> const &lhs);
add friendship to a non template operator.friend bool operator ==(ValueIter const&rhs,ValueIter const&lhs);和朋友bool operator ==(ValueIter
const&rhs,ValueIter const&lhs);将友谊添加到非模板运算符。 -
friend bool operator==<>(ValueIter const &rhs, ValueIter const &lhs);
,friend bool operator==<>(ValueIter<T> const &rhs, ValueIter<T> const
friend bool operator==<T>(ValueIter const &rhs, ValueIter const &lhs);
,friend bool operator==<T>(ValueIter<T> const &rhs, ValueIter<T> const
add friendship to the template operator (just for the type with matchT
)friend bool operator == <>(ValueIter const&rhs,ValueIter const&lhs);, friend bool operator == <>(ValueIter
const&rhs,ValueIter const friend bool operator == (ValueIter const&rhs ,ValueIter const&lhs);, friend bool operator == (ValueIter const&rhs,ValueIter const为模板运算符添加友谊(仅适用于匹配T的类型) -
template <typename U> friend bool operator==(ValueIter<U> const &rhs, ValueIter<U> const &lhs);
add friendship to the template operator (for any typeU
(which may differ ofT
))template
friend bool operator ==(ValueIter const&rhs,ValueIter const&lhs);将友谊添加到模板运算符(对于任何类型U(可能不同于T))
==<>
is used in the second point and is really == <>
.
== <>用于第二点,实际上是== <>。