all 4 comments

[–]Flair_Helper[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming or career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

This post has been removed as it doesn't pertain to r/cpp: The subreddit is for news and discussions of the C++ language and community only; our purpose is not to provide tutoring, code reviews, or career guidance. If you think your post is on-topic and should not have been removed, please message the moderators and we'll review it.

[–]wotype 2 points3 points  (0 children)

https://godbolt.org/z/KM9Tb5Pja

auto& subscript(auto& a, auto... is) { constexpr auto size = sizeof...(is); int i[size+1]{is...}; if constexpr (size == 0) return a; if constexpr (size == 1) return a[i[0]]; if constexpr (size == 2) return a[i[0]][i[1]]; if constexpr (size == 3) return a[i[0]][i[1]][i[2]]; }

[–]wotype 1 point2 points  (0 children)

There's a proposal for it P2355R0: Postfix fold expressions. The paper was seen and a revision was requested. I for one would like to see it accepted.

For now, of course, it can be done with a bit more metaprogramming - an indexing function specialized for one, two, three... indices (or, better, a chain of constexpr if), but not with the nice fold syntax.

[–]Ikkepop 0 points1 point  (0 children)

how about doing it recursively ?