C++ Logo

std-proposals

Advanced search

Re: Specific Override Specifier

From: Michał Policht <michal_at_[hidden]>
Date: Fri, 20 Mar 2020 13:21:00 +0100
> But we are modifying the override of B::lock.. lock_mutex isn't affected
> and doesn't become a different function, nor is the scope of
> "lock_mutex" affected by it. >
> Consider also:
>
> using B::foo(int) override = foo(int);
> using C::foo(int) override = foo(int);
> using D::foo(int) override = bar(int);


OK, I suppose you want to express something like `vtable[D::foo] =
A::bar`, but mentioned proposal is more generic, it helps to deal with
other kinds of problems, not only overrides. When you type ` using g =
B::f` it says: I want `g` to be another name of `B::f`.

Addressing your example, the question is whether `bar(int)` in the
following hides `D::foo` from the `foo` override lookup.

```
using bar = D::foo;

void bar(int) override; // overrides and hides(?) D::foo

void foo(int) override; // overrides B::foo and C::foo
```

Even if not, it's not a big deal to provide separate overrides and call
some common foo().

```
using foo_b = B::foo;
using foo_c = C::foo;

void foo_b(int) override { common_foo(int); }
void foo_c(int) override { common_foo(int); }

void common_foo(int);
```


>
> The thing on the left side (function to override) can appear once.
> Whereas the other way around, it's the thing on the right side that can
> appear once, e.g. you can't do the following:
>
> using foo(int) = B::bar(int);
> using bar(int) = B::bar(int);

Actually the relationship could be surjective, just like `using my_int =
int` and `using your_int = int` refer to same `int` type.


>
> There is no logical problem with one function overriding multiple
> virtual base functions, but the other way around is impossible.
>
> So I think you have it backwards, the thing that is being assigned is
> the override, not what the function overrides.
>
> I hope you can agree that, with this case considered, it makes more
> sense for the override to be on the left side of the = symbol. Tell me
> your thoughts.
>
> Also, I think using X override = Y; might need to be a separate proposal.
>

What I'm trying to do is to apply existing name aliasing proposal to
your problem. What drives my choices here is a matter of existing rules,
trying to make things consistent and generic. If we'd going to
deconstruct the language, I would probably opt for something completely
different, not involving `using` declaration.

Regards,
Michał

Received on 2020-03-20 07:23:51