Tech·Ed North America 2011

Modern Native C++ Development for Maximum Productivity

Download this episode

Download Video

Description

C++0x, the next C++ standard, is almost upon us and it contains the most important updates to the language since the mid-90s. These new features bring more expressiveness and power to the native C++ developer. Microsoft Visual Studio 2010 has added support for some of these key features in order to enable these modern programming techniques. This session clarifies what features are in Microsoft Visual C++ 2010 and what is yet to come. It illustrates how new constructs such as lambda expressions enable better use of existing libraries and how your code can be simpler, safer and faster all at the same time. Also, see how simple it can be to implement concurrency in your application and how Visual C++ 2010 supports the difficult task of debugging parallelized code. If you are itching to show off how C++ is one of the coolest languages on the planet, this talk is for you!
For more information, check out this course on Microsoft Virtual Academy:

Day:

4

Code:

DEV303

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • Ferruccio

      The type of prime *is* typeable. It is of type: std::function< bool(int) >

    • Marc

      @Ferruccio

      That's actually not quite right. A Lambda of the form [](int x) { return true; } is _assignable_ to std::function<bool(int)>, but that's not quite the same as saying the type of the lambda _is_ std::function<bool(int)>.

      Consider:
      bool function(int);

      struct functor
      {
      bool operator()(int);
      };

      //...
      std::function<bool(int)> f;

      // I can assign a function pointer to f, is f of type bool (*)(int)?
      f = &function;

      // I can assign a functor to f, is f of type functor?
      f = functor();

      // And now a lambda
      f = [](int x){ return false; };

      In the above example, f is none of a function pointer, a function object, or a lambda, yet it accepts all of them just fine.

      Lastly, consider:

      decltype([](int x) { return false; }) x = [](int x){ return false; };

      In the above, I am trying really really hard to get the correct type of the lambda so I can name the type explicitly, yet (in VS2010 anyway) that won't compile. So, it seems that indeed, the type of a lambda is untypable, even though that doesn't stop us from assigning it to std::function or doing other useful things with it.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.