Open utterances-bot opened 3 years ago
"proposals that might be included in the next C++ Standard"
These are some of my wishes for changes to the core language:
1) Variable default initialisation should take the existing type if this type is known. This means that this would be legal:
auto l = vect.size(), n{};
where n is default initialised to be the same type as l. Currently this reports an error - but the compiler knows the type of n!
2) initialisation within a do loop. Currently, there is no way to define a variable within a do loop and use it within the while condition - as the scope of defined variables end at the } before the while. I propose this:
do (int I {}) { // Use I } while (I); // OK as I still in scope
3) Optional specify begin/end iterators for range-for
This should be allowed as optional:
for (const auto& it : myvect(myvect.rbegin(), myvect.rend()) // use it
Hence you can reverse iterate over a container, or only over a specified range etc. Yes - you can do something like this using ranges - but for something simple like this, it's often an overkill.
4) Specify the number of levels to jump for the break and continue statements. Currently you can only break/continue back 1 level - for switch, for/while/do etc. It would be useful if you could optionally specify how many levels to break/continue on. 1 meaning 1 level as now with no number specified. 0 meaning all levels. So
// 1. for (; ;) //2. for (; ;) break; // Go to end of for 2 as of now break 1; // Same as break; break 2; // Go to end of for 1. exit for 2 and for 1 break 0; // go to end of all nested levels continue 2; // exit level 2 for loop and continue with level 1 for
For new library features, I would suggest classes that enable support for:
and SG20 (Education) should produce 'dummies guide' to new features. We don't all speak 'standard' language!
Regarding number #3, check out ranges in C++20. What you're looking for is this:
std::ranges::reverse_view rv {v}; for (auto && val : rv) {...}
I'd also support adding #4 although the much maligned "goto" already achieves the same ends and is actually easier to follow.
Re #3. Yes, I know about ranges (as mentioned)- but the point is to to be able to specify a range without having the 'baggage' of using std::ranges.
Five Awesome C++ Papers for the Q2 2021 and C++23 Status - C++ Stories
The work on C++23 continues! Without the face-to-face meetings, the Committee gathers online and discusses proposals and new additions to the language. See my latest report on what changed in C++ in April, May, and June 2021. Let’s start! Disclaimer: the view presented here is mine and does not represent the opinion of the ISO C++ Committee.
https://www.cppstories.com/2021/q2-cpp-papers/