c++0x characteristics Part 1:lambdas,auto in VC10, and Static_assert

Source: Internet
Author: User
Tags expression visual studio visual studio 2010

Brief introduction

This series of articles describes the C + + 0x features supported in Microsoft Visual Studio 2010 and currently has three components.

Part 1: Introduces the lambdas, gives new meaning to the auto, as well as the static_assert;

Part 2 (one, two, three): The right value reference (Rvalue References) is introduced;

Part 3: An expression type (Decltype) is introduced

This article is part 1.

The Visual C + + compiler with the Microsoft visual Studio 20,109-month Community Technology Preview (CTP) provides support for four c++0x language features, namely Lambdas,auto,static_assert, and Rvalue References (right value quote, no longer translate the word later). Today, I'll detail the first three features. (I will soon be contributing an entire length of the article to explain the right value reference, simply because it will increase the length of this long article).

First, there are some things to say:

1, today's article is brought to you by developers of the Stephan T. lavavej,visual C + + library as well as C, A, and the T Reader Letters column. Note that as a developer of the library, I do not implement these features. That was Jonathan caves, a front-end compiler developer, a member of the Election standards committee and all the "ninjas" (little-known gurus).

2, I have Visual C + + compiler in VS 2010 referred to as VC10 (vs 2008 contains Vc9,vs 2005 contains VC8, and so on. -10 is no shorter than 2010)

3,c++0x refers to the upcoming C + + standard, which is now being drafted. (The C + + Standards Committee expects it to be completed in 2009, called C + + 09; Jokingly said that "X" would be hexadecimal if it was postponed to 2010 or later.) C + + 98 and C + + 03 refer to the current C + + standard. (not reviewing history here, C + + Standard 2003 is just the original "patch" version of the C + + 1998 standard, and for most people, the difference between the two can be ignored.) C + + 03 and C + + 0x look similar, but completely different.

4, I would like to thank the Standard Committee for developing these wonderful and useful and artistically rich features. They also provide important documentation on the following sites:

c++0x Language Features:

Http://open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2705.html

C++0X Library Features:

Http://open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2706.html

c++0x Drafts in progress:

Http://open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2798.pdf

5, there will always be bugs (though hopefully not too much), which is the main purpose of releasing the CTP (letting users test for bugs). Please report these bugs to us through Microfsoft.

Now, let's look at these features!

Lambdas

In C + + 0x, the lambda expression implicitly defines and constructs an unnamed function object that is like a handwritten function object. The following is an example of a lambda "Hello,world" entry level:

C:\Temp>type meow.cpp
#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;
}
C:\Temp>cl /EHsc /nologo /W4 meow.cpp > NUL && meow
0 1 2 3 4 5 6 7 8 9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.