Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are fold expressions a C++14 or a C++1z feature?

https://isocpp.org/std/the-standard states that the working draft N4296

contains the C++14 standard plus minor editorial changes.

I noted that N4296 §5.1.3 contains a specification of "Fold expressions". I thought this to be a feature which did not make it to the official C++14 standard.

Are fold expressions part of C++14 or is this addition in N4296 one of those minor editorial changes?

like image 413
jotik Avatar asked Apr 02 '16 18:04

jotik


People also ask

What are fold expressions in C++17?

C++17 brought fold expressions to the language. This interesting feature allows to write expressive code, that almost seems magical. Here is a two-posts recap on how fold expressions work (this post) and how they can improve your code (the next post).

What are fold expressions and how do they work?

Here is a two-posts recap on how fold expressions work (this post) and how they can improve your code (the next post). A fold expression is an instruction for the compiler to repeat the application of an operator over a variadic template pack. Let’s take an example.

How to use fold expressions to reduce the parameter pack?

With fold expressions, you can directly reduce the parameter pack with the help of the binary operator. Here is the output of the program. Now to the two variations of fold expression that result in four different forms of fold expressions. At first, fold expression can have a default value. That value depends on the binary operator.

What is a fold in C++11?

(C++11) Reduces ( folds) a parameter pack over a binary operator. ( pack op ... ) any of the following 32 binary operators: + - * / % ^ & | = < > << >> += -= *= /= %= ^= &= |= <<= >>= == != <= >= && || , .* ->*. In a binary fold, both op s must be the same. Note that the open and closing parentheses are part of the fold expression.


1 Answers

  • N3937 is the C++14 DIS (Draft International Standard). N3936 (no longer publicly available, but can be dug out from the github repo) is N3937 with a different cover.

  • N4141 is the C++14 IS; it's the DIS plus some editorial changes. It's not publicly available.

  • N4140 is the pre-Urbana working draft; it's N4141 plus more editorial changes.

  • N4296 is the post-Urbana working draft. It includes C++17 features voted in at the committee's Urbana meeting.

Fold expressions is a C++17 feature.

like image 62
T.C. Avatar answered Sep 29 '22 00:09

T.C.