2

Is there support for lambda expressions from C++ 0x in Visual Studio 2008 SP1? Example below throws me syntax errors. Is there any '-Cpp0x' flag for compiler or something?

#include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>

using namespace std;

int main() 
{
  vector<int> v;

  for (int i = 0; i < 10; ++i) 
  {
    v.push_back(i);
  }

  for_each(v.begin(), v.end(), [](int n) { cout << n << " "; });
  cout << endl;
}

Thank you in advance.

Serge
  • 7,706
  • 5
  • 40
  • 46
Jarek
  • 55
  • 1
  • 5

3 Answers3

3

See Stackoverflow question #146381

Simply put: no. Visual Studio 2010 will support C++0x to some extent, but I'm unsure if that will include lambda expressions.

Community
  • 1
  • 1
Tamas Czinege
  • 118,853
  • 40
  • 150
  • 176
1

You can... kind of.

The Visual C++ 2008 compiler doesn't support lambdas, but you can certainly use the Visual C++ 2010 compilers from Visual Studio 2008!!

Just install Visual C++ 2010 Express, and then open Visual Studio 2008 and go to:

Tools->Options->Project and Solutions->VC++ Directories

and then add the following entries:

  • For the Win32 platform, insert $(ProgramFiles)\Microsoft Visual Studio 10.0\VC\bin at the beginning, and $(ProgramFiles)\Microsoft Visual Studio 10.0\Common7\IDE at the end.

  • For the x64 platform, insert $(ProgramFiles)\Microsoft Visual Studio 10.0\VC\bin\amd64 at the beginning.

Now you can use all the VC++ 2010 features from Visual Studio 2008! :)

user541686
  • 205,094
  • 128
  • 528
  • 886
0

Visual studio doesnot support, instead use Boost library.

Vinay
  • 4,743
  • 7
  • 33
  • 43