Skip to content

Provide unbounded_variant with a non-template polymorphic base #121

@pavel-kirienko

Description

@pavel-kirienko

I suggest we introduce a public base class for cetl::unbounded_variant that contains a subset of its API that is not dependent on the size, footprint, copyability, and movability properties of the class. This base class will enable certain more advanced usages that are not currently possible.

At the minimum, the polymorphic base should allow the following:

  • Check if the variant has_value.
  • reset the variant.
  • The freestanding get and get_if should be defined on the polymorphic base instead of the concrete type.
  • Add type() const -> type_id similarly to index() const -> std::size_t in the regular variant to enhance runtime introspection.

I think this can be retrofitted quite easily with just a few changes. @serges147 could you please confirm?

It would be super nice to support visitation similar to std::visit but I see no way to do it via the non-template base. We could perhaps do it at the implementation level but that is a lot less useful so perhaps not worth the trouble.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions