C++ Logo

std-proposals

Advanced search

Re: New separator for function arguments

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Thu, 6 Jan 2022 14:10:24 -0500
On Thu, Jan 6, 2022 at 4:22 AM Bo Persson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On 2022-01-06 at 05:28, 柳田達也 via Std-Proposals wrote:
> > I would like to propose new separator for arguments as shown below:
> >
> > void func(int a; int b); // not "," but ";"
> >
> > The motivation to add this feature is that multidimensional subscript
> > operator in P2128R3 (
> > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2128r3.pdf
> > <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2128r3.pdf> )
> > may cause confusion.
> > If subscript operator could take multiple arguments, there could be two
> > types of usages.
> > The first usage is multidimensional access as explained in P2128R3 and
> > the second one is subrange access as follows:
>

"Subrange access" isn't indexing, though. And we already have prior art for
subrange access in at least two ways:

// 1
auto s = "hello world"s;
auto subs = s.substr(6, 5);

// 2
std::valarray<int> a = {1,2,3,4,5};
auto suba = a[std::slice(1, 3, 1)];

If you want a slicing operator, it seems like it might be a good idea to
provide
    auto operator[](std::slice how) const;
or define your own (slice method / slice datatype). But probably not to
introduce a whole new function-call syntax.

–Arthur

Received on 2022-01-06 13:10:37