C++ Logo

std-discussion

Advanced search

Re: subscripting fold expression

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 25 Apr 2019 20:22:49 -0700
On Thursday, 25 April 2019 15:42:16 PDT Nicolas Lesser via Std-Discussion
wrote:
> I'd expect it to return a std::tuple or some other tuple like type right?
> Consider this:
>
> Without fold expressions, suming a variadic argument list is a pain. That's
> why fold expressions were created. But take your example; it can be easily
> writen without any recursion or ugly code:
>
> template <typename T, typename ...Ts>
> constexpr auto foo(T t, Ts ...is) {
> return std::make_tuple(t[is]...);
> }
>
> Also I find your proposed code to be more confusing and harder to understand
> than the above.

I expect you're right in terms of what the OP is expecting. But if you talk
about fold expression for operator[], I kinda expect the very unuseful
expansion of foo(t, a0, a1, a2, a3) to be:

  t[a0][a1][a2][a3];

I don't see how this is a likely usecase.

Besides, how do you expand the zero-production of operator[] ?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2019-04-25 22:24:29