Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend cetl::rtti_helper to support non-default constructor of the first base type. #111

Open
serges147 opened this issue Mar 27, 2024 · 1 comment

Comments

@serges147
Copy link
Contributor

serges147 commented Mar 27, 2024

Currently, I have to write something like this to inherit from TestBase and have RTTI support:

struct TestCopyableOnly final : TestBase
{
    explicit TestCopyableOnly(const char payload) : TestBase(payload) { ... }
    // rtti
    static constexpr type_id _get_type_id_() noexcept { ... }
    CETL_NODISCARD void* _cast_(const type_id& id) & noexcept override { ... }
    CETL_NODISCARD const void* _cast_(const type_id& id) const& noexcept override { ... }

Ideally make it possible to write like this:

struct TestCopyableOnly final : rtti_helper<type_id_type<...>, TestBase>
{
    using base = rtti_helper<type_id_type<...>, TestBase>::base; // TBD
    explicit TestCopyableOnly(const char payload) : base(payload)) { ... }

Although, I'm not sure how it will better tune api of rtti_helper so that:

  1. easier make the using base = ... declaration (without duplicating type id!)
  2. support multiple inheritance (like struct DogCat : rtti_helper<type_id_type<...>, Dog, Cat> { ... }) while passing all (variadic?) arguments to at least the first base constructor (the Dog(some_args) one).
@pavel-kirienko
Copy link
Member

The helper is expected to have limited applicability and every now and then you'll find that it doesn't suit your use case. I think amending its ctor such that it forwards the arguments to the first base is sensible but anything beyond that can be safely considered out of the scope (which is to say that in your Dog Cat example you can't use the helper unless Cat is default-constructible).

Not sure if there's a way to avoid restating the template parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants