Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
msgpack_check_eq.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "msgpack.hpp"
5#include <cstddef>
6#include <string_view>
7
8namespace msgpack {
9
13template <msgpack_concepts::HasMsgPack T>
14bool msgpack_check_eq(const T& v1, const T& v2, const std::string_view& error_message)
15{
16 bool had_error = false;
17 // hack: const_cast is used to allow the msgpack method to be called on const objects without doubling up the
18 // function definition.
19 const_cast<T&>(v1).msgpack([&](auto&... args1) { // NOLINT
20 const_cast<T&>(v2).msgpack([&](auto&... args2) { // NOLINT
21 // Capture args1 and args2 as const ref tuples and then iterate through each, comparing the values
22 auto args1_tuple = std::tie(args1...);
23 auto args2_tuple = std::tie(args2...);
24 constexpr auto size1 = std::tuple_size<decltype(args1_tuple)>::value;
25 const char* current_label = "";
26 constexpr_for<0, size1, 1>([&]<size_t i>() {
27 if constexpr (i % 2 == 0) {
28 current_label = std::get<i>(args1_tuple);
29 } else {
30 auto arg1 = std::get<i>(args1_tuple);
31 auto arg2 = std::get<i>(args2_tuple);
32 if (arg1 != arg2) {
33 if (!had_error) {
34 info(error_message);
35 }
36 had_error = true;
37 info(current_label, ": ", arg1, " != ", arg2);
38 }
39 }
40 });
41 });
42 });
43 return !had_error;
44}
45} // namespace msgpack
#define info(...)
Definition log.hpp:93
bool msgpack_check_eq(const T &v1, const T &v2, const std::string_view &error_message)
Ensures that two msgpack objects are equal by applying the msgpack method to both and comparing the r...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13