-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
I'd love it if any_regular had a holds<T> routine (similar to std::variant). It would make checking for the type of the thing within the regular much more terse and easy to read.
Old:
if (my_regular.type_info() = typeid(dictionary_t)) {...New:
if (my_regular.holds<dictionary_t>()) {...Another option would be a routine that returns an optional reference wrapper, so if the underlying type matches the caller doesn't have to go back in to get the value. This example is a free function but a member function would work as well:
template <class T>
inline std::optional<std::reference_wrapper<const T>> holds_cast(const adobe::any_regular_t& x) {
if (x.type_info() == typeid(T)) {
return std::reference_wrapper<const T>(x.cast<T>());
}
return std::nullopt;
}Metadata
Metadata
Assignees
Labels
No labels