diff --git a/include/cppkafka/topic_partition.h b/include/cppkafka/topic_partition.h index a3874db..a77b07a 100644 --- a/include/cppkafka/topic_partition.h +++ b/include/cppkafka/topic_partition.h @@ -112,6 +112,11 @@ public: */ void set_offset(int64_t offset); + /** + * Compare the (topic, partition) for less-than equality + */ + bool operator<(const TopicPartition& rhs) const; + /** * Print to a stream */ diff --git a/src/topic_partition.cpp b/src/topic_partition.cpp index f6ba410..64231ee 100644 --- a/src/topic_partition.cpp +++ b/src/topic_partition.cpp @@ -28,11 +28,13 @@ */ #include +#include #include #include "topic_partition.h" using std::string; using std::ostream; +using std::tie; namespace cppkafka { @@ -77,6 +79,10 @@ void TopicPartition::set_offset(int64_t offset) { offset_ = offset; } +bool TopicPartition::operator<(const TopicPartition& rhs) const { + return tie(topic_, partition_) < tie(rhs.topic_, rhs.partition_); +} + ostream& operator<<(ostream& output, const TopicPartition& rhs) { return output << rhs.get_topic() << "[" << rhs.get_partition() << "]"; }