C++ Logo

std-proposals

Advanced search

Base class name aliases - status clarification

From: Daniel Milyutin <DMilyutin_at_[hidden]>
Date: Mon, 13 Jan 2020 11:35:45 +0000
Greetings to all,

I'd like to clarify status of "base class alias". I'll repeat my initial text (see below this message) and summarize (so far) my short talk with Ville Voutilainen <ville.voutilainen_at_[hidden]<mailto:ville.voutilainen_at_[hidden]>> for better picture.

Ville Voutilainen <ville.voutilainen_at_[hidden]<mailto:ville.voutilainen_at_[hidden]>> kindly provided links to couple of similar proposals



One is (http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2009/n2881.html) by James Widman & Thorsten Ottosen closest to my text. However, it is of 2009.

I wonder if there was any update since then?
James, Thorsten,
if you read this, can you clarify your intents on your proposal and status.



Second proposal (http://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4225.html) is by Ville.
It requires new keyword to be introduced and has (IMO) quite verbose and unobvious syntax. (Sorry, Ville.)
Ville, I'm going to stick with my syntax. If you'd like we could discuss this and maybe collaborate.

As for me, I'm happy with first proposal. If authors would complete this feature I'll just relax and wait for it.
But, as I can see, there are no activities since 2009.
I need an advice. What should I do to move this forward?

Please, give your feedback on this feature and clarify if you find it useful and achievable. Thanks.

Best Regards,
Daniel.


From: Daniel Milyutin
Sent: Wednesday, November 20, 2019 5:48 PM
To: 'std-proposals_at_[hidden]' <std-proposals_at_[hidden]>
Subject: Base class name aliases

Greetings to all readers,

My name is Daniel.

My proposal is on reducing boilerplate when inheriting and having alias of baseclass.

Quite common situation is so far.
You inherit from (templated) class and want to have some aliases for base class names.
Like so:
///code starts
template<typename T1, typename T2, typename T3>
class Derived: public Base<T1, T2>, protected Policy<T3>
{
protected:
  using help = Policy<T3>;
public:
  using super = Base<T1, T2>;
  void foo()
  {
    super::foo(help::someMethod());//
  }
};
///code ends
Non-templated case may be seen in the same fashion.
Templated version is more typing and more errors to do.

In example above one have to type-in (copy-paste - to be honest) names of base classes.
When base class changes you have to type its name twice and actually you may miss update for alias.

To reduce this boilerplate let us consider the following example of syntax:
/// code starts
template<typename T1, typename T2, typename T3>
class Derived: public Base<T1, T2> -> super, protected Policy<T3> -> help
{
public:
  void foo()
  {
    super::foo(help::someMethod());//ex.
  }
};
/// code ends
Herein let it be assumed that alias is with same access as in inherited classes
(i.e. super is public and help is protected).
Symbol "->" is just for sake of example. Think of this as some syntax allowing to have this functionality.
More options for syntax will be described a little further.
To control access to alias from derived class one may have this syntax:
/// code starts
template<typename T1, typename T2, typename T3>
class Derived: public Base<T1, T2> ->private super, protected Policy<T3> -> public help
...
/// code ends
Note "private super" and "public help".

The rule options for default behavior when access is not specified may be:
(in order of my current preference):
RO1) when there is no [opt-access] use access same as of base class
RO2) when there is no [opt-access] use alias access as private
RO3) when there is no [opt-access] use alias access as public

Syntax options are(to my estimation of most likeliness):
SO1) public Base<T1, T2> -> [opt-access] super
SO2) public Base<T1, T2> = [opt-access] super
SO3) [opt-access] using super = public Base<T1, T2>
SO4) [opt-access] super = public Base<T1, T2>
SO5) public Base<T1, T2> typedef [opt-access] super
SO6) public Base<T1, T2> [opt-access] typedef super
SO5) public Base<T1, T2> using [opt-access] super
SO6) public Base<T1, T2> [opt-access] using super
SO7) public Base<T1, T2>([opt-access] super)
SO8) public Base<T1, T2> as [opt-access] super
SO9) public Base<T1, T2> => [opt-access] super

There may be more. I'd prefer less verbose 1).
But also I'd like to distinguish from "->" operator. So I actually wrote "=>" operator.
I'm aware there are no operators "=>" or "as" in C++.and probably won't be.
That's it.
_________

That is my first proposal.
I don't know how further process of consideration and discussion goes.
And I hope I send this to right e-mail.

Best Regards,
Daniel.
Confidentiality Notice: This message (including attachments) is a private communication solely for use of the intended recipient(s). If you are not the intended recipient(s) or believe you received this message in error, notify the sender immediately and then delete this message. Any other use, retention, dissemination or copying is prohibited and may be a violation of law, including the Electronic Communication Privacy Act of 1986.

Received on 2020-01-13 05:38:19