C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Small C compatibility extensions for array

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Wed, 26 Oct 2022 00:25:44 +0200
wt., 25 paź 2022 o 22:15 Federico Kircheis via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> On 25/10/2022 21.57, Thiago Macieira via Std-Proposals wrote:
> > On Sunday, 23 October 2022 12:28:41 PDT Bo Persson via Std-Proposals wrote:
> >> So instead of f(int [static 42]) you could use f(std::array<int, 42>&).
> >>
> >> Being C compatible is a very minor convenience here.
> >
> > Strictly speaking, that's not the same thing. The "static 42' means "at least
> > 42", not "exactly 42". See https://cigix.me/c17#6.7.6.3.p7
> >
> > To declare "exactly 42", the C standard decided to overload yet another
> > keyword: restrict. You write:
> >
> > f(int [static restrict 42]);
> >
> > C++ does not want this.
> >
>
> We already have span that covers this (and other) use-cases, even if you
> cannot write f({1,2,3, ...,42})
>
> (and https://wg21.link/P2447 did not get accepted, so it is not going to
> change)


And more importantly we have `&`:
```
void foo(int (&foo)[42]);
template<int I>
void bar(int (&foo)[I]);
```

even more, we can do something like this:
```
template<typename T, int I>
void foo(T (&&f) [I])
{
   auto z = std::move(f[0]);
}
void bar()
{
    foo({1,2,3,4});
    foo({std::string{"aaa"}});
    foo({std::make_unique<int>()});
}
```

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-10-25 22:25:56