C++ Logo


Advanced search

Re: [wg14/wg21 liaison] Multidimensional subscript operator

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 27 Apr 2021 00:51:05 +0300
On Tue, 27 Apr 2021 at 00:30, Uecker, Martin
<Martin.Uecker_at_[hidden]> wrote:
> > > Of course, in C++ you could also use a template
> > > instead of a macro:
> > >
> > > c_array<int, 3> x; // same type as int[3]
> >
> > Yeah, funny how we already have std::array that looks like that, and
> > it just solves this problem, more in the next.
> Except one is compatible with everything else in the
> world and one is a different one C++ introduced in addition
> to makes things... simpler?

It does make things simpler. We can relegate legacy arrays to very
contained portions
of our code, and use the more regular facilities elsewhere. Sure, we
need an array
for the implementation guts for std::vector and std::array, and std::span covers
the rest. But we don't need to pass or return legacy arrays, or
otherwise manipulate
them, pretty much *anywhere*. So whether they're regular or whether
they fit in with
the rest becomes irrelevant.

> Only if you close your eyes and ignore the types for which this
> currently does not work (because C++ inherited them from C and
> still uses C's declarator syntax and which it still needs for
> compatibility with the rest of the world).
> Changing the declarator syntax would make it truly work for
> all types. *That* would be regular.

Well, that's if you can *change* the declarator syntax, instead of adding to it.
Which takes a loooong time. Perhaps we should instead consider adding a regular
array type to C and have C++ adopt it, too.

> > Well, with a reinvented type, the declarator syntax works fine, and we
> > don't need to invent
> > new declarator syntaxes. So I'd step very cautiously before agreeing
> > with that conclusion
> > of yours about what we should do.
> In this way C++ created a parallel universe of new types but
> will probably still not be able to get rif of the C arrays
> any time soon. And by ignoring them you make them even more
> the irregular corner case instead of a proper part of the
> type system. This is then a self-fulfilling prophecy.

Sure, but it works splendidly well. And it probably becomes an
argument against P1997;
right now, the legacy arrays are contained in their dusty corners.
P1997 makes them
crawl out.

> When I check what applications I personally use,
> many of them are written in C.

I use some myself, the GNOME ones. I can't fathom why they bother.
Feel free to add destructors to C and we can talk. :)

Received on 2021-04-26 16:51:18