Skip to content

Commit

Permalink
add missing overloads to TraceID's operator== and operator!= (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoffredo authored Mar 17, 2023
1 parent 9093a98 commit 66be1fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/datadog/trace_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,9 @@ bool operator!=(TraceID left, std::uint64_t right) {
return left != TraceID{right};
}

bool operator==(std::uint64_t left, TraceID right) { return right == left; }

bool operator!=(std::uint64_t left, TraceID right) { return right != left; }

} // namespace tracing
} // namespace datadog
2 changes: 2 additions & 0 deletions src/datadog/trace_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ bool operator==(TraceID, TraceID);
bool operator!=(TraceID, TraceID);
bool operator==(TraceID, std::uint64_t);
bool operator!=(TraceID, std::uint64_t);
bool operator==(std::uint64_t, TraceID);
bool operator!=(std::uint64_t, TraceID);

} // namespace tracing
} // namespace datadog
12 changes: 12 additions & 0 deletions test/test_trace_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,23 @@ TEST_CASE("TraceID comparisons") {
// First, comparing integers with the `TraceID.low`.
REQUIRE(TraceID{12345} == 12345);
REQUIRE_FALSE(TraceID{12345} != 12345);

REQUIRE(TraceID{12345} != 54321);
REQUIRE_FALSE(TraceID{12345} == 54321);

REQUIRE(TraceID{6789, 12345} != 12345);
REQUIRE_FALSE(TraceID{6789, 12345} == 12345);

// And the opposite argument order.
REQUIRE(12345 == TraceID{12345});
REQUIRE_FALSE(12345 != TraceID{12345});

REQUIRE(54321 != TraceID{12345});
REQUIRE_FALSE(54321 == TraceID{12345});

REQUIRE(12345 != TraceID{6789, 12345});
REQUIRE_FALSE(12345 == TraceID{6789, 12345});

// Second, comparing trace IDs with other trace IDs.
struct TestCase {
int line;
Expand Down

0 comments on commit 66be1fb

Please sign in to comment.