От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 04.09.22 23:06 | ||
Оценка: | +1 |
for(auto i: n.items())
{
//...
}
Неудобно же?This problem may be worked around using init-statement:
for (T thing = foo(); auto& x : thing.items()) { /* ... */ } // OK
От: | DiPaolo | ||
Дата: | 05.09.22 01:45 | ||
Оценка: |
If range-expression returns a temporary, its lifetime is extended until the end of the loop, as indicated by binding to the forwarding reference __range, but beware that the lifetime of any temporary within range-expression is not extended.
for (auto& x : foo().items()) { /* .. */ } // undefined behavior if foo() returns by value
От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 05.09.22 10:47 | ||
Оценка: |
DP>If range-expression returns a temporary, its lifetime is extended until the end of the loop, as indicated by binding to the forwarding reference __range, but beware that the lifetime of any temporary within range-expression is not extended.
DP>DP>for (auto& x : foo().items()) { /* .. */ } // undefined behavior if foo() returns by value DP>
От: | DiPaolo | ||
Дата: | 05.09.22 11:00 | ||
Оценка: |
If range-expression returns a temporary, its lifetime is extended until the end of the loop, as indicated by binding to the forwarding reference __range, but beware that the lifetime of any temporary within range-expression is not extended.
T thing = foo();
for (auto& x : thing.items()) { /* ... */ }
for (auto& x : foo().items()) { /* ... */ }
От: | Андрей Тарасевич | ||
Дата: | 08.09.22 15:46 | ||
Оценка: |
for(auto i: n.items())
M>{
M> //...
M>}
M>Неудобно же?M>This problem may be worked around using init-statement:
M>for (T thing = foo(); auto& x : thing.items()) { /* ... */ } // OK M>