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"
6#include <cstddef>
7#include <string_view>
8
9namespace msgpack {
10
14template <msgpack_concepts::HasMsgPack T>
15bool msgpack_check_eq(const T& v1, const T& v2, const std::string_view& error_message)
16{
17 bool had_error = false;
18 // hack: const_cast is used to allow the msgpack method to be called on const objects without doubling up the
19 // function definition.
20 const_cast<T&>(v1).msgpack([&](auto&... args1) { // NOLINT
21 const_cast<T&>(v2).msgpack([&](auto&... args2) { // NOLINT
22 // Capture args1 and args2 as const ref tuples and then iterate through each, comparing the values
23 auto args1_tuple = std::tie(args1...);
24 auto args2_tuple = std::tie(args2...);
25 constexpr auto size1 = std::tuple_size<decltype(args1_tuple)>::value;
26 const char* current_label = "";
27 constexpr_for<0, size1, 1>([&]<size_t i>() {
28 if constexpr (i % 2 == 0) {
29 current_label = std::get<i>(args1_tuple);
30 } else {
31 auto arg1 = std::get<i>(args1_tuple);
32 auto arg2 = std::get<i>(args2_tuple);
33 if (arg1 != arg2) {
34 if (!had_error) {
35 info(error_message);
36 }
37 had_error = true;
38 info(current_label, ": ", arg1, " != ", arg2);
39 }
40 }
41 });
42 });
43 });
44 return !had_error;
45}
46} // namespace msgpack
void info(Args... args)
Definition log.hpp:70
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