barretenberg
Loading...
Searching...
No Matches
msgpack_apply.hpp
1#pragma once
2
3#include "msgpack.hpp"
4#include "msgpack_impl/drop_keys.hpp"
5
6namespace msgpack {
10template <msgpack_concepts::HasMsgPack T> void msgpack_apply(const auto& func, auto&... args)
11{
12 std::apply(func, msgpack::drop_keys(std::tie(args...)));
13}
19template <msgpack_concepts::HasMsgPack T> void msgpack_apply(const T& value, const auto& func)
20{
21 auto static_checker = [&](auto&... value_args) {
22 static_assert(msgpack_concepts::MsgpackConstructible<T, decltype(value_args)...>,
23 "MSGPACK_FIELDS requires a constructor that can take the types listed in MSGPACK_FIELDS. "
24 "Type or arg count mismatch, or member initializer constructor not available.");
25 };
26 // We must use const_cast as our method is meant to be polymorphic over const, but there's no such concept in C++
27 const_cast<T&>(value).msgpack([&](auto&... args) { // NOLINT
28 std::apply(static_checker, msgpack::drop_keys(std::tie(args...)));
29 msgpack_apply<T>(func, args...);
30 });
31}
32} // namespace msgpack
Definition: concepts.hpp:16