Skip to content

Feature Request: bool any_regular::holds<T>() #130

@fosterbrereton

Description

@fosterbrereton

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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions