C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Infer member type (`auto`) when using default member initializer
From: Dusan Jovanovic (dusan.jovanovic_at_[hidden])
Date: 2019-11-14 04:57:50


Hi,

We would like to create a proposal for extending the scope of auto keyword
and to allow for its usage for declaring class members when using default
member initialization.

struct Foo {

    auto bar = makeBar();

};

In our codebase we encountered a need for this macro:

#define AUTO_MEMBER(NAME, ...) decltype(__VA_ARGS__) NAME = __VA_ARGS__;

To be used as such:

struct Foo {

    AUTO_MEMBER(bar, makeBar())

};

But this has its limitations and a language support for this use case would
be nice.

Is there a reason why this was not done so far? Would this be something
worth pursuing?

Regards,

Dusan Jovanovic



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups