C++ Logo

std-discussion

Advanced search

Rationale for no auto arrays?

From: Eyal Rozenberg <eyalroz1_at_[hidden]>
Date: Wed, 23 Feb 2022 02:13:11 +0200
tl;dr: Why can't we write:

     auto arr[2] = { 1, 2 };

and have that compile?

--------

Longer version:

When the auto keyword was repurposed for C++11, and perhaps in later
discussions about expanding its use - was the possibility of using auto
for the types of arrays discussed? If so, can I get a reference to such
discussion, or to papers accepted/rejected which discuss this?

I don't quite see why we these statement:

     auto my_initializer_list = { 1, 2 };
     int arr[2] = { 1, 2 };

should compile (the former in C++17), but

     auto arr[2] = { 1, 2 };

should not. And this seems doubly strange, seeing how we can use all of:

    const auto
    auto&
    auto*

in variable definitions. Why is pointerification ok, but arrayfication
isn't?

Eyal

PS - My motivation is wanting to initialize a fixed-size array with
expressions which return a complex type I would rather not have to
specify explicitly.

Received on 2022-02-23 00:13:15