Date: Fri, 26 Apr 2019 00:42:16 +0200
Christof Meerwald via Std-Discussion wrote:
> Just noticed that I can't fold a subscripting expression, i.e.
> something like:
>
> template<typename T, typename ... II>
> constexpr auto foo(T t, II ... i)
> {
> return (t [] ... [] i);
> }
>
> Is this intentionally not allowed?
>
>
> Christof
>
> --
>
> http://cmeerw.org sip:cmeerw at cmeerw.org
> mailto:cmeerw at cmeerw.org xmpp:cmeerw at cmeerw.org
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
Maybe I'm just not creative enough but what would it do? In your example, what is the return value of `foo`?
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.
> Just noticed that I can't fold a subscripting expression, i.e.
> something like:
>
> template<typename T, typename ... II>
> constexpr auto foo(T t, II ... i)
> {
> return (t [] ... [] i);
> }
>
> Is this intentionally not allowed?
>
>
> Christof
>
> --
>
> http://cmeerw.org sip:cmeerw at cmeerw.org
> mailto:cmeerw at cmeerw.org xmpp:cmeerw at cmeerw.org
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
Maybe I'm just not creative enough but what would it do? In your example, what is the return value of `foo`?
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.
-- - Nicolas
Received on 2019-04-25 17:43:56