boost::tuple 带成员函数指针

boost::tuple with member function pointer

出于某种原因,我收到此错误消息

invalid operands of types 'void (S::* const)()' and 'void (S::* const)()' to binary 'operator<'

对于此代码段:

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>

struct S
{
    void f() {}
};

typedef void(S::*tdef)();

int main()
{
    boost::tuple<tdef> t1(&S::f);
    boost::tuple<tdef> t2(&S::f);
    return t1 < t2;
}

Boost 文档对在元组中使用成员函数指针守口如瓶(除了它们是有效元素),所以我真的不知道可能是什么问题或这些 'const'限定符进入表达式。

有什么提示吗?

元组将尝试在函数指针上进行比较,您只能比较函数指针是否相等。另请参考this question

Function pointers are not relationally comparable in C++. Equality comparisons are supported, except for situations when at least one of the pointers actually points to a virtual member function (in which case the result is unspecified).