Skip to content

Provide unbounded_variant with a non-template polymorphic base #121

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.

Activity

  1. changed the title [-]Provide unbounded_variant with a polymorphic base[/-] [+]Provide unbounded_variant with a non-template polymorphic base[/+] on May 7, 2024
  2. added theissue type on Mar 6, 2025
  3. changed the issue type fromtoon Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions