Re: [boost] FOREACH / C++ "for" proposal

In-Reply-To: <427FB7C9.9030708@systemhaus-gruppe.de> sstrasser@systemhaus-gruppe.de (Stefan Strasser) wrote (abridged):
Although it doesn't seem to say whether "vec" is hoisted, and the given translation suggests that it isn't.
maybe "hoisting" was not the right word, I only know it from a post by eric.
"Hoisting" is fine for the purposes of this thread.
what I meant was copy-the-value-of-end()-at-the-start-of-the-loop. and the proposal does that, see 3.
It says end(vec) is hoisted, but doesn't say whether vec itself is hoisted. In "for (int i: vec )" is vec evaluated once or twice? I believe BOOST_FOR evaluates it exactly once. The translation given in the proposal is: using std::begin; // enable ADL using std::end; // ditto for( auto __begin = begin(vec), __end = end(vec); __begin != __end; ++__begin ) { int i = *__begin; std::cout << i; } which apparently evaluates vec twice. A variable __end is introduced explicitly for end(vec), but there is no analogous variable __vec. I guess we ought to find out for sure which it will be, and then make BOOST_FOR do the same. -- Dave Harris, Nottingham, UK.

"Dave Harris" <brangdon@cix.compulink.co.uk> wrote in message news:memo.760661@cix.compulink.co.uk... | In-Reply-To: <427FB7C9.9030708@systemhaus-gruppe.de> | sstrasser@systemhaus-gruppe.de (Stefan Strasser) wrote (abridged): | > > Although it doesn't seem to say whether "vec" is hoisted, and the | > > given translation suggests that it isn't. | > | > maybe "hoisting" was not the right word, I only know it from a post by | > eric. | | "Hoisting" is fine for the purposes of this thread. | | | > what I meant was copy-the-value-of-end()-at-the-start-of-the-loop. | > and the proposal does that, see 3. | | It says end(vec) is hoisted, but doesn't say whether vec itself is | hoisted. In "for (int i: vec )" is vec evaluated once or twice? I believe | BOOST_FOR evaluates it exactly once. The translation given in the proposal | is: | | using std::begin; // enable ADL | using std::end; // ditto | for( auto __begin = begin(vec), | __end = end(vec); | __begin != __end; ++__begin ) | { | int i = *__begin; | std::cout << i; | } | | which apparently evaluates vec twice. | A variable __end is introduced | explicitly for end(vec), but there is no analogous variable __vec. | | I guess we ought to find out for sure which it will be, and then make | BOOST_FOR do the same. thanks for bringing this up. the intend is, of course, that the expression is only evaluated once. so auto&& __vec = vec; would be needed. -Thorsten
participants (2)
-
brangdon@cix.compulink.co.uk
-
Thorsten Ottosen