
David Hall wrote:
Anything like "while(int i <for_all_in> vec) cout << i;" isn't all that feasible (without being really hackish), since you need to maintain some sort of state inside of something that lives beyond each while statement, but specifically not in for_all_in, since we want to be able to iterate over the same container twice.
Well, I didn't really mean for that to be taken _too_ seriously, I just was throwing out general concepts.
The best I can come up with is this: (This could be prettified if we had auto, with the added bonus of allowing for autoselection of const versus non-const iterators.) for_all_in_iterator<std::vector<int> > i; while( i <for_all_in> vec) std::cout << *i << std::endl;
where for_all_in_iterator is essentially a specialized form of boost::optional<>. I don't think you can get around using an iterator, unless you're willing to sacrifice either for_all_in's reentry or status as pseudo-keyword.
Gosh! You didn't need to do all that!
Either way, I added my code in, with a few edits to yours, to allow for non-const RhsT. Ideally, there'd be a for_all_in_const_iterator version, but that's pretty easy.
Yes, you need the overloads for rvalue arguments, to do things like 'if(6 <is_in> foo) ...' I put that in after reading up on 'perfect forwarding' (although I used the equivilant '(T const & foo)' and did it for LhsT _and_ RhsT, just to 1-up you :D)