C++ Logo


Advanced search

Infer member type (`auto`) when using default member initializer

From: Dusan Jovanovic <dusan.jovanovic_at_[hidden]>
Date: Thu, 14 Nov 2019 11:57:50 +0100

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?


Dusan Jovanovic

Received on 2019-11-14 05:00:26