ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

comparison operators for messages

asked 2014-09-27 01:09:50 -0600

brice rebsamen gravatar image

do I have to provide them myself:

namespace std_msgs {
bool operator== (const Header &h1, const Header &h2)
{
  return h1.frame_id==h2.frame_id && h1.stamp==h2.stamp && h1.seq==h2.seq;
}
}

namespace geometry_msgs {
bool operator== (const Point &p1, const Point &p2)
{
  return p1.x==p2.x && p1.y==p2.y && p1.z==p2.z;
}
bool operator== (const Quaternion &q1, const Quaternion &q2)
{
  return q1.x==q2.x && q1.y==q2.y && q1.z==q2.z && q1.w==q2.w;
}
bool operator== (const Pose &p1, const Pose &p2)
{
  return p1.position==p2.position && p1.orientation==p2.orientation;
}
}

etc...

that's seems dumb. I checked the generated header files and no comparison operator is provided. The default constructor initializes things to 0, there is a serialization mechanism, etc. but not comparison operator. Am I missing a point? Is there a good reason to not provide these operators?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-09-27 10:23:45 -0600

dornhege gravatar image

Your example is actually quite well chosen: What does it mean for some poses to be equal? The only auto-generated way would be this one, e.g. comparing floats for equality. Is 3.00000001 really different from 3.0000002?

One could argue that float equality would be at least something, but in my opinion this might lead to people accidentally using that.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-27 01:09:50 -0600

Seen: 2,752 times

Last updated: Sep 27 '14