Mittwoch, 15. Dezember 2010

foreach for C++

In order to bring the foreach comfort from C# to C++ I found the following way to do so:

  1. Using boost library (a must have library for C++ developers)
  2. Go to make BOOST_FOREACH prettier
  3. Add usertype.dat into same directory where devenv.exe resists
  4. Add the words foreach and reverse_foreach to usertype.dat
  5. Restart Visual Studio

D’oh! The Code Snippet-Plug-In fails.

It should look like this:

image

But:

   1:  void BoostTests()


   2:  {


   3:      DbgLog(__FUNCTIONW__);


   4:   


   5:      boost::array<int, 3> myIntArray;


   6:      myIntArray[0] = 2;


   7:      myIntArray[1] = 8;


   8:      myIntArray[2] = 1976;


   9:   


  10:      int result = 0;


  11:   


  12:      foreach (int number, myIntArray)


  13:      {


  14:          result += number;


  15:      }


  16:  }


Keine Kommentare: