for(;;)
{
char c = stream.peek();
if(c == ' ') break;
loop body...
}for(char c; (c = stream.peek()) != ' '; )
{
} for(char c; (c = stream.peek()) != ' '; )
{
}
for (char c = stream.peek(); c != ' '; c = stream.peek)
In the era of auto and deduced types, this code is just ugly. And the weird nested assinment is another gross thing I hoped we could abandon
The feature under discussion will reevaluate the declaration aswell. Otherwise there would be no point in it at all compared to a for loop.
In my view, a while loop evaluates its condition everytime it finishes a revolution. If you extend the syntax of the condition, I don't understand why this simple principle should be changed in favour of syntactic similarities with a for loop, which is a different construct.
From the discussion with multiple people, I have seen that there are multiple "interpretations" of the feature on "if": one is that there is an init statement and a condition (the view of most people that participated so far in discussion) and the other interpretation is that the existing "declaration in if" syntax was extended to allow changing the default "if the name evaluates to true, then ..." by specifying a followup expression.
The syntax used in the Standard supports the first interpretation, however.
I take it from the discussion that the actual reason is "no one proposed it, and we think that the similarities but differences with the for statement would be confusing"
The feature under discussion will reevaluate the declaration aswell. Otherwise there would be no point in it at all compared to a for loop.
From the discussion with multiple people, I have seen that there are multiple "interpretations" of the feature on "if": one is that there is an init statement and a condition (the view of most people that participated so far in discussion) and the other interpretation is that the existing "declaration in if" syntax was extended to allow changing the default "if the name evaluates to true, then ..." by specifying a followup expression.
The syntax used in the Standard supports the first interpretation, however.
I take it from the discussion that the actual reason is "no one proposed it, and we think that the similarities but differences with the for statement would be confusing"
From the discussion with multiple people, I have seen that there are multiple "interpretations" of the feature on "if": one is that there is an init statement and a condition (the view of most people that participated so far in discussion) and the other interpretation is that the existing "declaration in if" syntax was extended to allow changing the default "if the name evaluates to true, then ..." by specifying a followup expression.
The syntax used in the Standard supports the first interpretation, however.
The reason is probably that with init and condition you can (I'm guessing that that would be allowed) write something like this:if(auto a = get_possible(), auto b = get_always(); a != null && b == 'x') {}else if(b == 'y') {}else {}
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
That is what is called a for loop....
Funny thing. I just wanted to do this.
std::weak_ptr<T> p;
...
...
while (std::shared_ptr<T> q = p; q!=null_ptr)
{
//do stuff with q
}
or something along these lines. I want q to be destroyed and reconstructed each pass through the loop, because I want the chance for the object to be destructed, if nobody _else_ is holding on to the object referenced by p.
I knew roughly about the if-with-initialization syntax, and so this was a 'natural' offshoot of that, and I was mildly surprised that it didn't exist.
std::weak_ptr<T> p;
while (std::shared_ptr<T> q = p.lock()) {// do stuff with q}