C++ 11 Feature Proposal: Inherited constructors

189 просмотров
Перейти к первому непрочитанному сообщению

Matthew Dempsky

не прочитано,
29 окт. 2014 г., 19:06:0129.10.2014
– Chromium-dev
C++11 adds a way to explicitly inherit base class constructors; e.g.:

    class Base {
     public:
      Base(int, double) { ... }
      Base(char*) { ... }
      ...
    };

    class Derived : public Base {
     public:
      // Similar to explicitly defining:
      //     Derived(int x, double y) : Base(x, y) {}
      //     Derived(char* z) : Base(z) {}
      using Base::Base;
      ...
    };

I'd like to see them allowed by the Chromium C++ style guide, but they're currently not listed at all on chromium-cpp.appspot.com.

My use case is I have some typedefs for a class, but they're purely an implementation detail, so it seems unfortunate to need to define them in the header.  As an alternative, I've found this seems to work nicely:

    foo.h:
        class Foo {
          ...
         private:
          struct FooKey;
          FooKey MakeKey(...);
          ...
        };

    foo.cc:
        #include "base/tuple.h"

        struct Foo::FooKey : public Tuple4<X, Y, Z, W> {
          using Tuple4<X, Y, Z, W>::Tuple4;
        };

        ...

Then I don't need to include base/tuple.h or any headers necessary for declaring X/Y/Z/W in the header, and I don't need to add boilerplate passthrough constructors myself.

Alex Vakulenko

не прочитано,
29 окт. 2014 г., 19:08:5229.10.2014
– Matthew Dempsky, Chromium-dev
The feature is called "Delegated Constructors" and we have a discussion thread for it: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/0zVA8Ctx3Xo

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Alex Vakulenko

не прочитано,
29 окт. 2014 г., 19:10:2429.10.2014
– Matthew Dempsky, Chromium-dev
Oh, sorry, I jumped the gun. You are talking about something completely different... Apologies.

Jeffrey Yasskin

не прочитано,
29 окт. 2014 г., 19:13:4829.10.2014
– Alex Vakulenko, Matthew Dempsky, Chromium-dev
Delegating and Inheriting constructors are different features.
However, http://msdn.microsoft.com/en-us/library/hh567368.aspx says
MSVC 2013 doesn't implement inheriting constructors, so they're out
for now.

On Wed, Oct 29, 2014 at 4:08 PM, Alex Vakulenko <avaku...@chromium.org> wrote:

Nico Weber

не прочитано,
29 окт. 2014 г., 19:18:0329.10.2014
– Jeffrey Yasskin, Alex Vakulenko, Matthew Dempsky, Chromium-dev
Matthew, can you send a patch to add a row for them (in the banned section for now, it seems)?

Matthew Dempsky

не прочитано,
29 окт. 2014 г., 19:20:1529.10.2014
– Jeffrey Yasskin, Alex Vakulenko, Chromium-dev
On Wed, Oct 29, 2014 at 4:13 PM, Jeffrey Yasskin <jyas...@chromium.org> wrote:
However, http://msdn.microsoft.com/en-us/library/hh567368.aspx says
MSVC 2013 doesn't implement inheriting constructors, so they're out
for now.

Matthew Dempsky

не прочитано,
31 окт. 2014 г., 21:18:5031.10.2014
– Nico Weber, Jeffrey Yasskin, Alex Vakulenko, Chromium-dev
Inherited constructors are now listed as banned in chromium-cpp.appspot.com, but I'm interested if anyone can suggest better wording and/or a better documentation link for the entry.  In a recent CL, I added a "using Base::Member;" declaration, and my reviewer thought the style guide disallowed *all* "using Base::X;" declarations, not simply the special case of "using Base::Base;".

Etienne Pierre-doray

не прочитано,
29 июл. 2016 г., 11:46:0029.07.2016
– Chromium-dev, tha...@chromium.org, jyas...@chromium.org, avaku...@chromium.org
https://msdn.microsoft.com/en-us/library/hh567368.aspx states that MSVC2015 supports inherited constructor.
The following code compile and execute correctly using MSVS2015:

class Base {
 public:
  Base(int) {}
  Base(double) {}
};

class Derived : public Base {
 public:
  using Base::Base;
};

int main() {
  Derived d1(3);
  Derived d2(3.0);
}

It seems like the reason for their ban was that MSVC2013 didn't implement them. I'd like to see them allowed now that MSVC2015 supports them.

Nico Weber

не прочитано,
29 июл. 2016 г., 13:15:2729.07.2016
– Etienne Pierre-doray, Chromium-dev, Jeffrey Yasskin, Alex Vakulenko
Sounds fine to me. Please send a CL that adds a use of that (to show that it works) and that moves the feature to the "allowed" list.

Jeremy Roman

не прочитано,
29 июл. 2016 г., 23:52:5429.07.2016
– Nico Weber, Etienne Pierre-doray, Chromium-dev, Jeffrey Yasskin, Alex Vakulenko, cxx

Peter Kasting

не прочитано,
3 нояб. 2016 г., 18:57:2103.11.2016
– etie...@google.com, Chromium-dev, Nico Weber, Jeffrey Yasskin, Alex Vakulenko
On Fri, Jul 29, 2016 at 8:46 AM, 'Etienne Pierre-doray' via Chromium-dev <chromi...@chromium.org> wrote:
It seems like the reason for their ban was that MSVC2013 didn't implement them. I'd like to see them allowed now that MSVC2015 supports them.

Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений