Add TopicPartition::operator<

This commit is contained in:
Matias Fontanini
2016-06-26 13:27:16 -07:00
parent 25ae15444e
commit ab9c2494e1
2 changed files with 11 additions and 0 deletions

View File

@@ -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
*/

View File

@@ -28,11 +28,13 @@
*/
#include <iostream>
#include <tuple>
#include <librdkafka/rdkafka.h>
#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() << "]";
}