Reflective programming: Difference between revisions

Content deleted Content added
Line 73:
import std;
 
constevalusing autoInfo = makeInvoker(std::meta::info refl, std::string methodName) {;
using String = std::string;
 
template <typename T>
using AlwaysFalse = std::always_false<T>;
template <typename T, T v>
using IntegralConstant = std::integral_constant<T, v>;
template <typename T>
using Vector = std::vector<T>;
 
consteval auto makeInvoker(Info& refl, const String& methodName) {
return [refl](auto&& instance) {
constexpr std::vectorVector<std::meta::infoInfo> members = std::meta::nonstatic_members_of(refl);
for (std::meta::infoInfo& member: members) {
if (std::meta::identifier_of(member) == methodName) {
return [&]<auto M>(std::integral_constantIntegralConstant<decltype(member), M>) {
instance.[:M: ]();
}(std::integral_constantIntegralConstant<decltype(member), member>{});
}
}
static_assert(always_falseAlwaysFalse<decltype(instance)>(), "Method not found");
};
}
Line 94 ⟶ 104:
 
// With reflection
constexpr auto reflFoo = ^^Foo;
auto invokePrint = makeInvoker(reflFoo, "printHello");
invokePrint(foo);