But wait, I think I may have found a way to salvage my do-while proposal. Currently, the C++ standard specifies
do <http://nongnu.org/hcb/#statement> statement while ( <http://nongnu.org/hcb/#expression> expression ) ;
But what if we also added
do( <http://nongnu.org/hcb/#for-init-statement> init-statement ) <http://nongnu.org/hcb/#statement> compound_statement while ( <http://nongnu.org/hcb/#expression> expression ) ;
Compound statements require braces and so the syntactic/semantic ambiguity is removed.
It is a bit clunky, but would work.
From: Richard Hodges <***@gmail.com>
Sent: Sunday, October 28, 2018 1:33 AM
To: std-***@isocpp.org
Subject: Re: [std-proposals] Re: Do ... while structure improvement
On Fri, 26 Oct 2018 at 19:29, <***@gmail.com <mailto:***@gmail.com> > wrote:
Good point about the introduced âdoâ ambiguity. Looking at your example, Iâm not even sure the ambiguity could be resolved _semantically_. Shame â¹
I introduced the try-catch idea merely for âcompletenessâ/orthogonality (Iâm not a heavy user of exceptions myself), but the idea is as follows: You acquire some value from somewhere and attempt to perform computation on it, but if something goes awry, you throw it for someone else to handle:
try (MyObject val = some_acquired_value()) {
do_something_useful_with(val);
}
catch ( OverflowException e) {
throw(val); // so someone else can do something useful with it
}
// but you donât want val lying around here
This is an interesting case, because for me one of the most annoying things about c++'s try blocks is that the variables don't escape the braces. What I mean to say is that very often you do want at least one of the variables "lying around here" :)
consider this impossible case:
NotDefaultConstructible x; // illegal
try
{
x = NotDefaultConstructible::construct_may_throw(...);
x.something_that_may_throw();
y = x.some_property();
}
catch(...)
{
x = NotDefaultConstructible::recovery_mode();
}
// now use x;
We currently cannot write this - we are forced to hold x in an optional or unique_ptr - which while solving the language expression problem, has nothing to do with the intent of the algorithm - x is simply not logically optional in this case.
The answer of course is to wrap the operations involving x into a few smaller functions. But sometimes we don't want to. Essentially we're forced into something like this:
auto make_x = [&y] {
try {
x = NotDefaultConstructible::construct_may_throw(...);
x.something_that_may_throw();
y = x.some_property();
return x;
}
catch(...) {
return NotDefaultConstructible::recovery_mode();
}
};
auto x = make_x();
// use x
I think there are (at least) two opposing arguments here:
1. Obviously you should be forced to express this code in a function because the more single-responsibility functions you have the less complexity you have.
2. This action is so trivial that I don't want to be forced to express it through an artificial function.
From: Richard Smith <***@metafoo.co.uk <mailto:***@metafoo.co.uk> >
Sent: Monday, October 22, 2018 7:29 PM
To: std-***@isocpp.org <mailto:std-***@isocpp.org>
Cc: ***@ncomputers.org <mailto:***@ncomputers.org>
Subject: Re: [std-proposals] Re: Do ... while structure improvement
On Fri, 19 Oct 2018 at 15:24, <***@gmail.com <mailto:***@gmail.com> > wrote:
I'm late to the party (and maybe this has already made it in), but I'd also like to see 'do(init) { ... } while(predicate);', to prevent 'init' scope leakage.
`do` does not have mandatory braces, so parsing that would be quite challenging, and it would probably introduce lots of syntactic ambiguities. For example:
int **p, **x;
void f() {
do (int (**p) = x) (*p)[0] = 1; while (true);
}
... would be ambiguous between declaring a variable named p in a do-initializer and using it in the body, and a function-call expression whose callee is (int (**p) = x) and whose argument is *p.
Analogously, it would be good to have (if we don't have it yet) 'try(init) {....} catch(blah) {...} catch(blaz) {....}', where the scope 'init' extends to the last catch block.
This wouldn't be ambiguous, but is it useful? Do you have a concrete use case for this?
--Zem
On Thursday, October 16, 2014 at 9:44:59 AM UTC-7, ***@ncomputers.org <mailto:***@ncomputers.org> wrote:
Thank you very much for your time and your answer!
We're now two, who proposes the same improvement!
I think, that the other two ideas are also good!
Best regards,
ncomputers.org <http://ncomputers.org>
El jueves, 16 de octubre de 2014 01:43:41 UTC-5, Markus Grech escribió:
I have suggested the same idea in this thread: https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/O1rpMw2dNwA
Note that my suggestion is more general. You may want to look at the discussion there.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org <mailto:std-proposals+***@isocpp.org> .
To post to this group, send email to std-***@isocpp.org <mailto:std-***@isocpp.org> .
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2b0ed6ec-12fb-415c-b940-5c66c27dfeb4%40isocpp.org <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2b0ed6ec-12fb-415c-b940-5c66c27dfeb4%40isocpp.org?utm_medium=email&utm_source=footer> .
--
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/i-0stW2WkXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposals+***@isocpp.org <mailto:std-proposals+***@isocpp.org> .
To post to this group, send email to std-***@isocpp.org <mailto:std-***@isocpp.org> .
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm2eWDcUcVgDaOQg4RBrh4UGmMHfgGDuPWeYKnZ-9sSfA%40mail.gmail.com <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm2eWDcUcVgDaOQg4RBrh4UGmMHfgGDuPWeYKnZ-9sSfA%40mail.gmail.com?utm_medium=email&utm_source=footer> .
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org <mailto:std-proposals+***@isocpp.org> .
To post to this group, send email to std-***@isocpp.org <mailto:std-***@isocpp.org> .
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/006801d46d51%24826da7b0%248748f710%24%40gmail.com <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/006801d46d51%24826da7b0%248748f710%24%40gmail.com?utm_medium=email&utm_source=footer> .
--
Richard Hodges
***@gmail.com <mailto:***@gmail.com>
office: +442032898513
home: +376841522
mobile: +376380212 (this will be *expensive* outside Andorra!)
skype: madmongo
facebook: hodges.r
--
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/i-0stW2WkXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to std-proposals+***@isocpp.org <mailto:std-proposals+***@isocpp.org> .
To post to this group, send email to std-***@isocpp.org <mailto:std-***@isocpp.org> .
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hYxZFCkfFe_0sdJJMRZk9WZUV7F9XZ3RSiUY4W-w2sWnw%40mail.gmail.com <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hYxZFCkfFe_0sdJJMRZk9WZUV7F9XZ3RSiUY4W-w2sWnw%40mail.gmail.com?utm_medium=email&utm_source=footer> .
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/00e701d46fb2%240064b9d0%24012e2d70%24%40gmail.com.