Rathelor
Rathelor

Reputation: 3

boost::tuple with member function pointer

For some reason I get this error message

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

for this code snippet:

#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 documents are very tight-lipped on using member function pointers in tuples (apart from they are valid elements), so I don't really have a clue what could be the problem or how those 'const' qualifiers got into the expression.

Any hint?

Upvotes: 0

Views: 272

Answers (1)

kittikun
kittikun

Reputation: 1909

Tuples will try to do the comparison on a function pointer and you can only compare function pointers for equality. Please also refer to 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).

Upvotes: 2

Related Questions