Variable tvm::ffi::reflection::overload_cast#
Defined in File registry.h
Variable Documentation#
-
template<typename ...Args>
constexpr details::OverloadCastImpl<Args...> tvm::ffi::reflection::overload_cast = {}# Cast an overloaded callable to a specific overload, picked by spelling out a parameter-type prefix that uniquely identifies it.
Args...is matched against the leading parameters of each candidate overload; the trailing parameter types (if any) are deduced from the picked overload’s signature. The returned value is a constexpr function pointer (member or free) and can be used wherever a typed function pointer is required, including as a non-type template argument.If the prefix matches multiple overloads (e.g. two overloads share the same leading parameters), the call is ambiguous and the caller must spell more parameters until exactly one overload matches.
class Pet { public: void Set(int); void Set(const std::string&); int Feed(const Cat*, int amount); int Feed(const Dog*, int amount); int Get(int); int Get(int) const; }; namespace refl = tvm::ffi::reflection; // Spell only the disambiguating first arg; the trailing `int amount` // is deduced from the picked overload's signature. auto p_feed_cat = refl::overload_cast<const Cat*>(&Pet::Feed); // decltype(p_feed_cat) == int (Pet::*)(const Cat*, int) // Spell the full parameter list when overloads share a prefix. auto p_set_int = refl::overload_cast<int>(&Pet::Set); // Const-qualified member — opt in via the const_ tag: auto p_get_const = refl::overload_cast<int>(&Pet::Get, refl::const_); // Use directly as a non-type template argument: template <auto F> struct UseAsTemplateArg { ... }; using U = UseAsTemplateArg<refl::overload_cast<const Cat*>(&Pet::Feed)>;
Note
When picking a const-qualified member function,
refl::const_must be passed as the second argument even when it is the only overload of its name. Without the tag the call does not compile.Note
This helper can be more permissive than some
overload_castvariants in existing packages that require the full parameter list to be spelled out: here a parameter-type prefix is accepted and the trailing types are deduced from the picked overload.