Skip to content

Commit 66be1fb

Browse files
authored
add missing overloads to TraceID's operator== and operator!= (#23)
1 parent 9093a98 commit 66be1fb

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/datadog/trace_id.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,9 @@ bool operator!=(TraceID left, std::uint64_t right) {
8484
return left != TraceID{right};
8585
}
8686

87+
bool operator==(std::uint64_t left, TraceID right) { return right == left; }
88+
89+
bool operator!=(std::uint64_t left, TraceID right) { return right != left; }
90+
8791
} // namespace tracing
8892
} // namespace datadog

src/datadog/trace_id.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ bool operator==(TraceID, TraceID);
4343
bool operator!=(TraceID, TraceID);
4444
bool operator==(TraceID, std::uint64_t);
4545
bool operator!=(TraceID, std::uint64_t);
46+
bool operator==(std::uint64_t, TraceID);
47+
bool operator!=(std::uint64_t, TraceID);
4648

4749
} // namespace tracing
4850
} // namespace datadog

test/test_trace_id.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,23 @@ TEST_CASE("TraceID comparisons") {
5757
// First, comparing integers with the `TraceID.low`.
5858
REQUIRE(TraceID{12345} == 12345);
5959
REQUIRE_FALSE(TraceID{12345} != 12345);
60+
6061
REQUIRE(TraceID{12345} != 54321);
6162
REQUIRE_FALSE(TraceID{12345} == 54321);
63+
6264
REQUIRE(TraceID{6789, 12345} != 12345);
6365
REQUIRE_FALSE(TraceID{6789, 12345} == 12345);
6466

67+
// And the opposite argument order.
68+
REQUIRE(12345 == TraceID{12345});
69+
REQUIRE_FALSE(12345 != TraceID{12345});
70+
71+
REQUIRE(54321 != TraceID{12345});
72+
REQUIRE_FALSE(54321 == TraceID{12345});
73+
74+
REQUIRE(12345 != TraceID{6789, 12345});
75+
REQUIRE_FALSE(12345 == TraceID{6789, 12345});
76+
6577
// Second, comparing trace IDs with other trace IDs.
6678
struct TestCase {
6779
int line;

0 commit comments

Comments
 (0)