#pragma once #include "reflection.hpp" #include #if __has_include() # include namespace eosio { template constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t>> { return boost::pfr::for_each_field(static_cast(t), static_cast(f)); } } // namespace eosio #endif namespace eosio { template constexpr auto for_each_field(T&& t, F&& f) -> std::enable_if_t>> { eosio_for_each_field((std::decay_t*)nullptr, [&](const char*, auto member) { if constexpr (std::is_member_object_pointer_v) { f(t.*member(&t)); } }); } template constexpr void for_each_field(F&& f) { eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) { if constexpr (std::is_member_object_pointer_v) { f(name, [member](auto p) -> decltype((p->*member(p))) { return p->*member(p); }); } }); } // Calls f(#fn_name, &T::fn_name) for every reflected member function of T. template constexpr void for_each_method(F&& f) { eosio_for_each_field((T*)nullptr, [&f](const char* name, auto member) { if constexpr (std::is_member_function_pointer_v) { f(name, member((T*)nullptr)); } }); } } // namespace eosio