/
Modern Programming with C++0x in Microsoft Visual C++ 2010 Modern Programming with C++0x in Microsoft Visual C++ 2010

Modern Programming with C++0x in Microsoft Visual C++ 2010 - PowerPoint Presentation

natalia-silvester
natalia-silvester . @natalia-silvester
Follow
346 views
Uploaded On 2019-06-28

Modern Programming with C++0x in Microsoft Visual C++ 2010 - PPT Presentation

Kate Gregory Gregory Consulting wwwgregconscomkateblog gregcons SESSION CODE DEV316 Required Slide Agenda Language and Library updates C0x and TR1 Lambdas auto std move uniqueptr ID: 760471

microsoft int ptr auto int microsoft auto ptr amp shared http vector msdn include required visual return slide resources

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Modern Programming with C++0x in Microso..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Modern Programming with C++0x in Microsoft Visual C++ 2010

Kate GregoryGregory Consultingwww.gregcons.com/kateblog, @gregcons

SESSION CODE: DEV316

Required Slide

Slide2

Agenda

Language and Library updates

C++0x and TR1

Lambdas, auto

std

::

move, unique_ptr

IDE improvements

Intellisense

– no

ncb

Navigate To , red squiggles

What there isn’t time for

MFC Updates

shared_ptr

,

nullptr

Rvalue

references, move constructors,

std

::move

More library additions

eg

copy_if

,

is_sorted

etc

Slide3

TR1 and C++0x

TR1 is Technical Report 1, released in 2005

C++0x is the upcoming C++ standard

Some of each were added in Visual C++ 2008 SP 1

(VC9SP1)

More are now in Visual C++ 2010

(VC10)

Slide4

Lambdas for C++

What’s a Lambda?

Lambda expression or lambda function: an expression that specifies an

anonymous function object

Imagine handing an operation or function (code) to some other operation or function

For generic work

For a functional style

For concurrency

For readability

Eliminate tiny functions

Slide5

Tiny Functions

#include <vector>

#include <

iostream

>

#include <algorithm>

using namespace

std

;

void

print_square

(

int

i)

{

cout

<< i*i <<

endl

;

}

int

main()

{

vector<

int

> v;

for_each

(

v.begin

(),

v.end

(),

print_square

);

}

Slide6

Why Does It Need a Name?

#include <vector>

#include <

iostream

>

#include <algorithm>

using namespace

std

;

int

main() {

vector<

int

> v;

for_each

(

v.begin

(),

v.end

(),

[](

int

i) {

cout

<< i*i <<

endl

;

} );

}

Slide7

Lambdas

DEMO

Slide8

Lambdas That Return Something

vector<

int

> v;

deque

<

int

> d;

 

transform(

v.begin

(),

v.end

(),

front_inserter

(d),

[](

int

n) { return n * n * n; }

);

transform(

v.begin

(),

v.end

(),

front_inserter

(d),

[](

int

n) -> double {

        if (n % 2 == 0) {

            return n * n * n;

        } else {

            return n / 2.0;

        }

    }

);

Slide9

Using Variables from Local Scope

v.erase

(

remove_if

(

v.begin

(),

v.end

(),

[x, y](

int

n)

{ return x < n && n < y; }

),

v.end

());

v.erase

(

remove_if

(

v.begin

(),

v.end

(),

[=](

int

n)

{ return x < n && n < y; }

),

v.end

());

for_each

(

v.begin

(),

v.end

(),

[&x, &y](

int

& r) {

       

const

int

old = r;

        r *=

2;

        

x

= y;

        y = old;     }

);

Slide10

Auto

Automatic type deduction

auto x = new

HugeObject

(42);

No more gnarly

iterator

declarations

for (auto it =

v.begin

(); it !=

v.end

(); ++it)

Powered

by

template

argument deduction rules

const

auto* p = new foo and

const

auto& r = bar work

Slide11

Rvalue referencesvector reallocation, etc. exploits move semanticsPerfect forwarding: make_shared<T>(), etc.unique_ptrNew member functions: cbegin(), cend(), etc.New algorithms: copy_if(), is_sorted(), etc.Code conversions: <codecvt>Exception propagation: exception_ptrDiagnostics: <system_error>

C++0x Standard Library in VC 2010

Slide12

Smart pointers

s

hared_ptr

Arrived in VC9 SP1

In VC10:

make_shared

unique_ptr

Like a

shared_ptr

without the sharing

Slide13

make_shared<T>()

VC9 SP1:shared_ptr<T> sp(new T(args));shared_ptr<T> sp(new T(args), del, alloc);VC10:auto sp = make_shared<T>(args);auto sp = allocate_shared<T>(alloc, args);

13

Slide14

unique_ptr

Supersedes auto_ptr, which is now deprecatedLightweight and performantNo reference counting overheadNoncopyable but movableWorks just fine in containers

14

Slide15

unique_ptr

DEMO

Slide16

Const iterators: cbegin and cend

vector<

int

> v;

for (auto i =

v.

begin

(); i !=

v.

end

(); ++i) {

// i is vector<

int

>::

iterator

}

for (auto i =

v.

cbegin

(); i !=

v.

cend

(); ++i) {

// i is vector<

int

>::

const_iterator

}

Slide17

Dev10 Architecture Changes

Intellisense

decoupled from navigation

No need to reparse entire solution after

header change

No more .

ncb

file – SQL CE store instead

Much quicker to insert/update single symbol

Intellisense

faster even in larger solutions

After a small code change

Switching build (e.g., debug to release)

Slide18

Dev10 New Features

Intellisense

…. that you can count on

Navigate To

Find a symbol

Red Squiggles

Without a build

Call Hierarchy

Calls From

Calls To

Replaces Call Browser

Slide19

New IDE Features

DEMO

Slide20

C++ Is Very Much Alive

Native code is still a fully supported way of life

Interop

is dramatically easier from C++

Templates offer power no other language can match

For both native-only and

interop

development

Microsoft is committed to C++

IDE improvements

MFC improvements

Language-level improvements

Slide21

Related Content

Required SlideSpeakers, please list the Breakout Sessions, Interactive Sessions, Labs and Demo Stations that are related to your session.

Breakout Sessions

DEV319

Scale

and Productivity for C++ Developers with Microsoft Visual Studio

2010

WSV325

Technical

Computing from Domain Analysis to Performance Profiling

Product

Demo

Stations

TLC-08

Microsoft

Visual Studio Languages (C#, VB.NET, C++, F#,

IronPython

,

IronRuby

)

Slide22

Track Resources

Visual Studio – http://www.microsoft.com/visualstudio/en-us/Soma’s Blog – http://blogs.msdn.com/b/somasegar/  MSDN Data Developer Center – http://msdn.com/data ADO.NET Team Blog – http://blogs.msdn.com/adonet WCF Data Services Team Blog – http://blogs.msdn.com/astoriateam EF Design Blog – http://blogs.msdn.com/efdesign

Required Slide

Track PMs

will supply the content for this slide, which will be inserted during the final scrub.

Slide23

Resources

Required Slide

www.microsoft.com/teched

Sessions On-Demand & Community

Microsoft Certification & Training Resources

Resources for IT Professionals

Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet

http://microsoft.com/msdn

Learning

Slide24

Complete an evaluation on

CommNet and enter to win!

Required Slide

Slide25

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31sthttp://northamerica.msteched.com/registration

 

You can also register at the

North

America 2011

kiosk

located at

registration

Join us in Atlanta next year

Slide26

©

2010 Microsoft

Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.

MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Slide27

Required Slide