   VS8 adds for each as a nonstandard unmanaged C++ extension
  Try it! The syntax is for each(type declaration in collection). I'm not compiling with /clr at all, and it works just fine. I've been using BOOST_FOREACH for awhile now (macro'd to foreach()), but it will be very hard to avoid this in the name of portability. :)   
  I'll be damned, it does work.#include <vector>#include <cstdlib>#include <algorithm>#include <iostream>using namespace std;int main(int argc, char* argv[]){vector<int> numbers;generate_n(back_inserter(numbers), 10, rand);for each(int i in numbers){cout<<i<<endl;}return 0;}EDIT: MSDN.   ;*holy cr%p!* [totally]Hmm, BOOST_FOREACH? I can't find it in the 1.33 dist... is it only in CVS?edit: Nevermind, found it here. YEAH!!!   ;#if _MSC_VER >= 1400#define foreach(var, container)if(false) {} else for each(var in container)#else#define foreach(var, container)BOOST_FOREACH(var, container)#endifNow it's portable.EDIT: ...as long as you only iterate over standard containers, since Boost.Foreach also supports iterating any Boost.Range.[Edited by - jdhardy on December 3, 2005 3:21:16 PM];  which is weird, because we already have std::for_each. If only they'd chosen to add lambdas instead.   ;  Well, boost::phoenix is underway...   ;  Now that's just plain messed up.  I mean, everyone knows there is no such thing as a for each construct in C++, so, WTF?  Adding obviously non-standard things like that is, in my opinion, not a very clever thing for Microsoft to do..   ;  Huh, that does look intersting. Still, I'd prefer real lambdas built into the compiler, rather than brittle template hacks which produce 200-line error messages.   ;Quote:Original post by SirLuthorNow that's just plain messed up.  I mean, everyone knows there is no such thing as a for each construct in C++, so, WTF?  Adding obviously non-standard things like that is, in my opinion, not a very clever thing for Microsoft to do..It's probably just an artifact from the C++/CLI for each construct. Basically it was already in the compiler anyways.   ;Quote:Original post by SiCraneQuote:Original post by SirLuthorNow that's just plain messed up.  I mean, everyone knows there is no such thing as a for each construct in C++, so, WTF?  Adding obviously non-standard things like that is, in my opinion, not a very clever thing for Microsoft to do..It's probably just an artifact from the C++/CLI for each construct. Basically it was already in the compiler anyways.Exactly. The for each, in construct was designed for C++/CLI, however in building it they also added support for arrays and standard C++ containers.   