Shouldn't something like this allowed?
for (auto&& obj : f())
for(a_big_struct_t&& obj : f())
{
auto && __range = range_expression ;
auto __begin = std::forward<decltype(__range)>(__range).begin();
auto __end = std::forward<decltype(__range)>(__range).end();
for ( ; __begin != __end; ++__begin) {
range_declaration = *__begin;
loop_statement
}
}
Sorry I write too fast and used auto accidentally.Change:
for (auto&& obj : f())by
for(a_big_struct_t&& obj : f())and it doesn't compile because the returned list is transparently a lvalue.My question is if that makes sense to be allowed.
for(auto && rng = f(); a_big_struct &&obj : move_range(rng))
Do you happen to know If the increment part of that proposal was also adopted and if not, why not?Thanks
--
---
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-discussion+unsubscribe@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/.
I found it a little odd that it wasn't part of the proposal.But I found it more surprising the committee adopted the proposal without requesting the increment part too.
So that made me wonder if there was something contentious about the increment part because it seems a glaring omission to me.
template<class Cont> moveable_container(Cont &&) -> moveable_container<std::decay_t<Cont>>;
I was anticipating the compiler incrementing the iterator then calling the code that was part of the increment step and giving the increment step code no access to the iterator.So it's a limitation not being able to see the iterator, but it allows the user to have other things that they may want to keep in step with the iterator (like increment their own integer or something) and have that code fire on 'continue' etc. Where as that is not possible with the current proposal as continue bypasses any such logic that is at the end of the loop.One could try to have a function in the increment step that receives the iterator, but that seems unusual compared the main loop constructs and what I'm suggesting is simpler and probably meets the typical use cases I can think of, which is that someone doesn't need the iterator but does need some logic that attempts to sync their own values with the iterator some how.To me it seems to make move this for loop construct closer to the original one which aids understanding and provides additional benefit too without taking it so far as to diverge into something that looks/works quite differently.Do you find anything objectionable about that idea?
Yes. A regular `for` loop needs an iteration expression to do iteration. Range-based `for` has iteration built-in; why would you need a user-defined expression?
Range-based for loops are supposed to be pretty simple. You have a range of values, and you're iterating over them. If you have some code that will be executed on every iteration, even in the event of a `continue`, then that makes the looping logic a lot less simple.If you need more complexity, then maybe range-based for is the wrong tool. I don't like the idea of trying to make range for able to do anything.
Yes. A regular `for` loop needs an iteration expression to do iteration. Range-based `for` has iteration built-in; why would you need a user-defined expression?Because it might not be that it's just iteration you want to do and that you want to do something after each iteration.
Such as increment some other counter that you want to keep in step. You might not need nor want to capture all that in a lambda or something just so that you can for each it and if you want to do 'continue' type operations to skip your loop part, you can't manage that easily from a lambda anyway.Range-based for loops are supposed to be pretty simple. You have a range of values, and you're iterating over them. If you have some code that will be executed on every iteration, even in the event of a `continue`, then that makes the looping logic a lot less simple.If you need more complexity, then maybe range-based for is the wrong tool. I don't like the idea of trying to make range for able to do anything.Maybe you're right sometimes there. But maybe you're not right all of the time. Isn't C++ a language where the user gets to decide?
I don't see (yet) any killer argument to not allow the facility. I've given a few examples above why it might be useful to allow it.
We only gave them an initializer to deal with a pernicious problem with temporary lifetime extension through function calls.