Re: [Boost-bugs] [Boost C++ Libraries] #1295: for each in VC8+

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #1295: for each in VC8+
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-10-19 16:54:25

#1295: for each in VC8+
  Reporter: NN | Owner: eric_niebler
      Type: Feature Requests | Status: closed
 Milestone: To Be Determined | Component: foreach
   Version: Boost 1.34.1 | Severity: Optimization
Resolution: wontfix | Keywords:
Comment (by NN):

 VC can iterate over native array and iterator ranges.
 In VC9 you can iterate over string literals too.

 There is no option to change variables, but this can be easily fixed with

 This what you can do with VC9 for each:
 #include <boost/array.hpp>
 #include <boost/range/iterator_range.hpp>

 #include <vector>

 template<typename T, size_t N>
 boost::array<T, N> make_array_range()
     boost::array<T, N> a;
     T c = 0;
     for each(T const& i in a)
         const_cast<T&>(i) = c++;
     return a;

 int main()
     for each(int i in make_array_range<int, 10>())
         printf("%d", i);

     typedef boost::array<int, 10> ints;
     ints a = make_array_range<int, 10>();
     boost::iterator_range<ints::iterator> x(a.begin(), a.end());
     for each(ints::const_reference i in x)
         printf("%d", i);

     for each(char% c in "asdf")
         printf("%c", c);

     typedef std::vector<int> vints;
     vints v(a.begin(), a.end());
     for each(vints::const_reference i in v)
         const_cast<vints::reference>(i) = 0;

 Of course this is not full replacement of Boost.Foreach.

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:56 UTC