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:  }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

About hfrmobile

Nice guy but with a sarcastic type of humor. I have combined hobby and profession and I am happy about this. At the moment I am holding MCP, MCSE (NT 4.0), MCTS and MCPD certificates. Having experience in developing software for more than 15 years. Started learning programming using Pascal, Assembler, C/C++. Also having experience with non-Microsoft products / programming languages (e.g. PHP). Most experiences at the moment: MySQL, MS-SQL, PL/SQL, ASP.NET, C#, Silverlight (Windows Phone) and WPF.
This entry was posted in Allgemein. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s