c++ when do you need to go native to c, c with c#? almost never if you are creating a new...
TRANSCRIPT
![Page 1: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/1.jpg)
![Page 2: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/2.jpg)
C++ Scenarios for C# DevelopersEric BattalioSenior Program Manager, Microsoft
![Page 3: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/3.jpg)
C++ScenariosSome slides about C++11More Scenarios
![Page 4: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/4.jpg)
When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component.
![Page 5: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/5.jpg)
You want to have fun developing againCoding closer to the metal is exciting, challenging, and fun. Expand your mind, pick up the STL, and learn from the C++ community.
![Page 6: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/6.jpg)
SymptomsBored writing the same old codeCurious about what C++ developers see in C++You want to feel the power of the STL and RAIIAttending C++ talks at Tech Ed
![Page 7: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/7.jpg)
ExamplesSuccessfully compiling your first post-Hello World appThat moment you start thinking in STLFollowing the C++ forums on Stack OverflowSpotting and fixing a bug in legacy C++ library
![Page 8: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/8.jpg)
Demo
Hello World (of course)
![Page 9: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/9.jpg)
GotchasTemptation to become template-writing MasterLost time debating when/where to use move/auto/...Stress of recruiters bugging you with C++ jobs
![Page 10: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/10.jpg)
C is pretty easy to learn but C++ is clearly complex. The basics are easy but it takes years to become a master in it (although C++11 is making it a bit easier).
![Page 11: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/11.jpg)
![Page 12: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/12.jpg)
very expert
much ninja
so impresswow!
![Page 13: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/13.jpg)
You may have heard a few things...Forget about 1995C++ is a living languageLanguage tweaks make it easier to do the right thingSpeed is only part of the story; code reuse is vitalVisual Studio is your friend and confidant
![Page 14: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/14.jpg)
Eighty twentyIn C++, a few things done well will get you most of the way to your solution(Or all the way)
Vri
adic
Tem
pla
tes
C+
+ 1
4
Cust
om
allo
cato
rs
Con
tain
ers
an
d
Alg
ori
thm
sR
efe
ren
ces,
Con
sta
nts
an
d R
an
ge-F
or
RTTI
Lam
bda-F
u
Ob
jects
an
d R
AII
Cla
ss intr
icaci
es
Move S
em
anti
cs
Overl
oadin
g n
ew
and d
ele
te
![Page 15: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/15.jpg)
Start with a good book
Good C++ books focus on C++11 and modern C++.
Don’t learn bad habits!
![Page 16: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/16.jpg)
Language EssentialsObjectsRAIIContainers and AlgorithmsReferences, Constants and Range-For
// Thanks to James McNellis!
![Page 17: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/17.jpg)
Language EssentialsObjectsRAIIContainers and AlgorithmsReferences, Constants and Range-For
![Page 18: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/18.jpg)
What is an Object?void f(){ int x{0};}
![Page 19: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/19.jpg)
Copying and Assignmentvoid f(){ int x{0};
int y{x}; // initialize y to be a copy of x y = x; // assign the value of x to y}
![Page 20: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/20.jpg)
Copying and Assignmentclass MyClass { /* ... */ };
void f(){ MyClass x{};
MyClass y{x}; // initialize y to be a copy of x y = x; // assign the value of x to y}
![Page 21: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/21.jpg)
Four Special Operationsvoid f(){ int x{0}; // Construction
int y{x}; // Copy Construction y = x; // Copy Assignment}// y.~int() // Destruction // x.~int()
![Page 22: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/22.jpg)
Four Special Operationsclass MyClass { /* ... */ };
void f(){ MyClass x; // Construction
MyClass y{x}; // Copy Construction y = x; // Copy Assignment}// y.~MyClass() // Destruction // x.~MyClass()
![Page 23: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/23.jpg)
Four Special Operationsclass MyClass{public: MyClass() { puts("Constructing"); } ~MyClass() { puts("Destroying"); } MyClass(MyClass const&) { puts("Copying"); } void operator=(MyClass const&) { puts("Assigning"); }};
![Page 24: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/24.jpg)
Four Special Operationsclass MyClass { /* previously defined */ };
void f(){ MyClass x; // Constructing
MyClass y{x}; // Copying y = x; // Assigning}// y.~MyClass() // Destroying // x.~MyClass() // Destroying
![Page 25: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/25.jpg)
Each object has an addressclass MyClass { /* ... */ };
void f(){ MyClass x;
MyClass* p{&x}; // p is a pointer to x // *p is another name for x}
![Page 26: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/26.jpg)
Different objects have different addresses
void f(){ MyClass x; MyClass y;
// Different objects have different addresses MyClass* px{&x}; // px points to x MyClass* py{&y}; // py points to y assert(px != py);}
![Page 27: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/27.jpg)
Special null pointer valuevoid f(){ MyClass* p{nullptr};}
![Page 28: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/28.jpg)
Pointers are objects toovoid f(){ MyClass x;
MyClass* px1{&x}; MyClass* px2{px1}; assert(px1 == px2);
px1 = nullptr; assert(px1 != px2);}
![Page 29: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/29.jpg)
Indirection is (mostly) implicit in C#// For value types, x and y are distinctint x = 0;int y = x;
y = 42;
// For reference types, x and y refer to the same objectList<int> x = new List<int>();List<int> y = x;
x.Add(1);
![Page 30: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/30.jpg)
Indirection is explicit in C++// x and *p denote the same objectint x{0};int* p{&x};
// Changes the value of x via *p*p = 42;
![Page 31: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/31.jpg)
Indirection is explicit in C++// x and *p denote the same objectMyClass x{};MyClass* p{&x};
// Changes the value of x via *p*p = get_thing();
![Page 32: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/32.jpg)
Lifetime and Storage DurationEach object has a lifetime…from the point at which the object comes into existence (is constructed)…to the point at which the object goes out of existence (is destructed)
Lifetime is associated with storage durationAutomatic storage durationStatic and thread-local storage durationDynamic storage duration
![Page 33: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/33.jpg)
Automatic Storage Durationvoid f(){ MyClass x{}; // Construction
MyClass y{x}; // Copy Construction y = x; // Copy Assignment
}// y.~MyClass() // Destruction // x.~MyClass() // Destruction
Lifetime of y Lifetime of x
![Page 34: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/34.jpg)
Static Storage DurationMyClass x{}; // Global variable
void f(){ static MyClass y{}; // Function-local static variable}
![Page 35: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/35.jpg)
Dynamic Storage Durationvoid f(){ MyClass* p{new MyClass{}};
delete p;}
Lifetime of *p
![Page 36: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/36.jpg)
Dynamic Storage DurationMyClass* f(){ MyClass* p{new MyClass{}}; return p;}
void g(){ MyClass* p{ f() }; delete p;}
![Page 37: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/37.jpg)
Initializationvoid f(){ int a = 0; // Copy initialization int b(0); // Direct initialization int c{0}; // Brace initialization int d{};}
![Page 38: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/38.jpg)
Initializationint global_int; // Zero-initialized
void f(){ int local_int; // Not initialized}
![Page 39: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/39.jpg)
Initializationvoid f(){ int local_int{}; MyClass local_MyClass{};}
![Page 40: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/40.jpg)
Language EssentialsObjectsRAIIContainers and AlgorithmsReferences, Constants and Range-For
![Page 41: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/41.jpg)
RAIIResource Acquisition Is Initialization(Scope-Bound Resource Management)
![Page 42: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/42.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ MyClass* p{new MyClass{}};
delete p;}
![Page 43: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/43.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ char* const buffer{new char[1024 * 1024]{}};
// ...use the buffer...
delete[] buffer;}
![Page 44: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/44.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ char* const buffer{new char[1024 * 1024]{}};
// ... throw std::runtime_error{"oops“}; // ...
delete[] buffer;}
![Page 45: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/45.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ char* const buffer{new char[1024 * 1024]{}};
// ... return; // ...
delete[] buffer;}
![Page 46: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/46.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ // Not actual C++ char* const buffer{new char[1024 * 1024]{}}; try { // ...use the buffer... } finally { delete[] buffer; }}
![Page 47: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/47.jpg)
RAII (Resource Acquisition Is Initialization)
void f(){ // Not actual C++ using (char* const buffer{new char[1024 * 1024]{}}) { // ...use the buffer... }}
![Page 48: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/48.jpg)
RAII (Resource Acquisition is Initialization)
void f(){ scoped_buffer buffer{new char[1024 * 1024]{}};
// ...use the buffer...
}// buffer.~scoped_buffer()
![Page 49: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/49.jpg)
RAII (Resource Acquisition is Initialization)
struct scoped_buffer{public: scoped_buffer(char* const p) : _p{p} { } ~scoped_buffer() { delete[] _p; } char* get() const { return _p; }
private: scoped_buffer(scoped_buffer const&) = delete; void operator=(scoped_buffer const&) = delete;
char* _p;};
![Page 50: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/50.jpg)
RAII (Resource Acquisition is Initialization)void f(){ scoped_buffer buffer{new char[1024 * 1024]{}};
// ...use the buffer...
}// buffer.~scoped_buffer()
![Page 51: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/51.jpg)
RAII (Resource Acquisition is Initialization)
void f(size_t const buffer_size){ std::unique_ptr<char[]> const buffer{new char[buffer_size]{}};
// ...code that uses the buffer...}
![Page 52: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/52.jpg)
RAII (Resource Acquisition is Initialization)
std::unique_ptr<char[]> f(size_t const buffer_size){ std::unique_ptr<char[]> buffer{new char[buffer_size]{}};
return buffer;}
![Page 53: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/53.jpg)
C++ Rule #1Never use delete in your codeAlways use a smart pointer to manage dynamic lifetimesunique_ptr, shared_ptr, ComPtr, etc.
![Page 54: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/54.jpg)
RAII (Resource Acquisition is Initialization)
std::mutex _sync;
void f(){ _sync.lock();
// ...synchronized code...
_sync.unlock();}
![Page 55: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/55.jpg)
RAII (Resource Acquisition is Initialization)
void f(){ std::unique_lock<std::mutex> lock(_sync);
// ...synchronized code...}
![Page 56: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/56.jpg)
RAII (Resource Acquisition is Initialization)
void f(char const* const file_name){ FILE* file(fopen(file_name, "r"));
// ...code that uses the file...
fclose(file);}
![Page 57: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/57.jpg)
RAII (Resource Acquisition is Initialization)
void f(char const* const file_name){ std::ifstream file(file_name);
// ...code that uses the file...}
![Page 58: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/58.jpg)
C++ Rule #1 (Revised)Never manage resources manually in your C++ codeAlways use RAII container typesUse existing RAII container types where possibleWrite your own when necessary
![Page 59: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/59.jpg)
Language EssentialsObjectsRAIIContainers and AlgorithmsReferences, Constants and Range-For
![Page 60: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/60.jpg)
Containers and Algorithmsstd::vectorstd::liststd::setstd::mapstd::unordered_setstd::unordered_map
ListLinkedListSortedSetSortedDictionaryHashSetDictionary
![Page 61: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/61.jpg)
Containers and Algorithmsstd::vector::insertstd::vector::push_backstd::vector::erasestd::vector::clear
List.InsertList.AddList.RemoveAtList.Clear
![Page 62: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/62.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
for (size_t i{0}; i != v.size(); ++i){ std::cout << v[i] << '\n';}
![Page 63: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/63.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
for (auto it{v.begin()}; it != v.end(); ++it) // std::vector<int>::iterator{ std::cout << *it << '\n';}
![Page 64: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/64.jpg)
Containers and Algorithmsstd::set<int> s{ 1, 2, 3, 4, 5, 6 };
for (auto it{s.begin()}; it != s.end(); ++it) // std::vector<int>::iterator not now!{ std::cout << *it << '\n';}
![Page 65: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/65.jpg)
Containers and Algorithmsstd::map<int, int> m{ { 1, 2 }, { 2, 4 }, { 3, 6 }, { 4, 8 }, { 5, 10 }, { 6, 12 }};
for (auto it{m.begin()}; it != m.end(); ++it){ std::cout << it->first << ': ' << it->second << '\n';}
![Page 66: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/66.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
for (auto it{v.begin()}; it != v.begin() + 3; ++it){ std::cout << *it << '\n';}
![Page 67: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/67.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
v.erase(v.begin() + 3); // Removes the 4v.insert(v.begin() + 2, 10); // Inserts a 10 after the 2
int const x{*(v.begin() + 1)}; // Gets the 2
*(v.begin() + 1) = 9; // Changes the 2 to a 9
int const y{*(v.begin() + 1000)}; // Invalid!
![Page 68: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/68.jpg)
Containers and AlgorithmsOkay, what about operations like sort and find?
v.sort(); // Nope; doesn't existv.find(4); // Nope; doesn't exist
![Page 69: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/69.jpg)
Containers and Algorithms
Iterators
Containers
Algorithms
![Page 70: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/70.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 3, 5, 2, 4, 6 };
std::sort(v.begin(), v.end());
![Page 71: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/71.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 3, 5, 2, 4, 6 };
auto const it{std::find(v.begin(), v.end(), 2)};if (it != v.end()){ std::cout << "I found a two!\n";}
![Page 72: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/72.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
if (std::binary_search(v.begin(), v.end(), 2)){ std::cout << "I found a two!\n";}
![Page 73: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/73.jpg)
Containers and Algorithmsfor_eachtransformall_ofany_offindFind_if
binary_searchlower_boundupper_boundequal_rangesortstable_sort
copy_ifuniquepartitionremoverotateand many more…
![Page 74: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/74.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::for_each(v.begin(), v.end(), [](int const x){ std::cout << x << '\n';})
![Page 75: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/75.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::transform(v.begin(), v.end(), v.begin(), [](int const x){ return x * x;});
![Page 76: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/76.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };std::vector<int> w(v.size());
std::transform(v.begin(), v.end(), w.begin(), [](int const x){ return x * x;});
![Page 77: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/77.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };std::vector<int> w;
std::transform(v.begin(), v.end(), std::back_inserter(w), [](int const x){ return x * x;});
![Page 78: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/78.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 3, 5, 2, 4, 6 };
std::sort(v.begin(), v.end(), [](int const lhs, int const rhs){ return lhs > rhs;});
![Page 79: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/79.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
bool const all_are_even(std::all_of(v.begin(), v.end(), [](int const x){ return x % 2 == 0;}));
![Page 80: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/80.jpg)
Containers and Algorithmsstd::vector<int> v{ 1, 2, 3, 4, 5, 6 };
std::set<int> s(v.begin(), v.end());
![Page 81: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/81.jpg)
Containers and Algorithmsint a[6]{ 1, 3, 5, 2, 4, 6 };
std::sort(begin(a), end(a));
![Page 82: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/82.jpg)
Containers and Algorithmsvoid f(int* const data, size_t const count){ int* const first{data}; int* const last {data + count};
std::sort(first, last);}
![Page 83: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/83.jpg)
Containers and Algorithmstemplate <typename Iterator, typename Function>bool all_of(Iterator const first, Iterator const last, Function const f){ for (Iterator it{first}; it != last; ++it) { if (!f(*it)) return false; }
return true;}
![Page 84: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/84.jpg)
Language EssentialsObjectsRAIIContainers and AlgorithmsReferences, Constants and Range-For
![Page 85: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/85.jpg)
Referencesvoid f(){ int x{0}; // x is an object
int& rx{x}; // rx is a reference to x // it is another name for x}
![Page 86: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/86.jpg)
Referencesvoid f(std::vector<int>& v){ // ...Use the vector...}
![Page 87: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/87.jpg)
constvoid f(){ int const x{0}; x = 42; // Invalid; x is const}
![Page 88: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/88.jpg)
constvoid f(){ int x(0);
int const& rx(x); int const* px(&x);
x = 42; // Ok, x is not const rx = 42; // Invalid; rx is const *px = 42; // Invalid; *px is const}
![Page 89: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/89.jpg)
constvoid f(std::vector<int> const& v){ // ...Use the vector but don't modify it...}
![Page 90: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/90.jpg)
Range-forvoid f(){ std::vector<int> v = { 1, 2, 3, 4 };
for (const auto& x : v) { std::cout << x << '\n'; }}
![Page 91: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/91.jpg)
autostd::vector<int> get_stuff();
void f(){ auto the_stuff = get_stuff();}
![Page 92: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/92.jpg)
I was once on a project where performance was important, so the core of the program was written in C++. Other people would use it on different platforms including Unix and Linux.
![Page 93: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/93.jpg)
You need portable codeWhen it comes to portable code, C++ is hard to beat. It is build on a rich heritage of compatibility.There are differences among compilers, but all provide a reasonable ISO C++ standard compliant experience.
![Page 94: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/94.jpg)
ScenarioCode needs to perform well on multiple devicesCode needs to be accessible on multiple devices
![Page 95: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/95.jpg)
SymptomsYou need features only accessible to native codePerformance concerns for managed language
![Page 96: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/96.jpg)
Examples<pattern: hamburger, UI layer on top, device API on bottom, meat is the C++ portable layer>
![Page 97: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/97.jpg)
Demo
Portable Code
![Page 98: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/98.jpg)
GotchasSource and build management complexityConformance differences
![Page 99: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/99.jpg)
I also use C++ when I need to access some specific features from CryptoAPI or create high performance stuff web server stuff.
If you are planning to develop a math intensive library such as a quant library, stochastic analysis, signal processing or alike, go with C++.
![Page 100: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/100.jpg)
You need to tune a managed applicationC# performs admirably across a range of applications.But!Sometimes application hot spots drive down performance and cannot be solved in native code alone.
![Page 101: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/101.jpg)
SymptomsProfiler exposes code that has already been optimizedCustom graphics UI is sluggishExcessive amounts of data marshalling
![Page 102: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/102.jpg)
ExamplesCrunching large amounts of data (image, audio)Excessive amounts of data marshallingLarge file processingComplex algorithms (financial, data structures)
![Page 103: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/103.jpg)
Demo
C++ AMP
![Page 104: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/104.jpg)
GotchasPremature optimizationTradeoffs (simplicity/maintainability for complexity)Missed or unforeseen causes (constrained by db)Installation and deployment
![Page 105: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/105.jpg)
I also use C++ when I need to access some specific features from CryptoAPI or create high performance stuff web server stuff.
If you are planning to develop a math intensive library such as a quant library, stochastic analysis, signal processing or alike, go with C++.
![Page 106: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/106.jpg)
Talking to older systemsOld systems never seem to die. Insurance, engineering, manufacturing, medical – many industries run on older applications. Submitting a claim or new part order may require specialized protocols.
![Page 107: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/107.jpg)
SymptomsCompany has a place you go to request tape loadsBusiness rules are a “black box”Reliance on bridging middleware
![Page 108: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/108.jpg)
ExamplesHealth care claims processing and adjudicationEngineering modelling Chemical processing and schedulingHome-grown, stove-pipe systemsJob systems
![Page 109: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/109.jpg)
GotchasAPIs might be brittle...and pickyPerformance mismatchError handling (return codes)
![Page 110: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/110.jpg)
You need to use existing code librariesCritical functionality vital to your project exist only in native C/C++ libraries.
![Page 111: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/111.jpg)
SymptomsSchedule or other pressures make rewrite impossibleSource is inaccessible and/or surrounded by folkloreFeature is already implemented in OSS libraryExisting code is compliant/certified/secureCustom hardware control
![Page 112: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/112.jpg)
ExamplesEDI transmission componentData cryptography servicesComputer visionAssembly line product quality hardwarePhysics, graphics, or other niche
![Page 113: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/113.jpg)
Demo
Consuming and extending APIs
![Page 114: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/114.jpg)
GotchasDependency on external development resourcesToo many cross-boundary callsData conversions (ascii / MBCS / Unicode / platform string...)Memory leaks, null pointers, security vulnerabilities
![Page 115: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/115.jpg)
Thank YouPing me any [email protected]
Follow Visual C++ Team Bloghttp://blogs.msdn.com/b/vcblog/
We want your suggestions, help us improve Visual Studio and Visual C++Visit Visual C++ on User Voice http://aka.ms/UserVoiceVisualCPP
![Page 116: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/116.jpg)
Favorite Things for C++ Developers in Visual Studio 2013, DEV-B223
Debugging Tips and Tricks in Visual Studio 2013, DEV-B352
Related content
What's New in Microsoft Visual Studio 2013 for C++ Developers, DEV-H223
Find me later in the Visual Studio booth, on Twitter @visualc or at [email protected]
![Page 117: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/117.jpg)
Resource 1
Track resources
Resource 2
Resource 3
Resource 4
Required Slide*delete this box when your slide is finalized
The PMs will supply the content for this slide, which will be inserted during the final scrub.
![Page 118: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/118.jpg)
Resources
Learning
Microsoft Certification & Training Resources
www.microsoft.com/learning
msdn
Resources for Developers
http://microsoft.com/msdn
TechNet
Resources for IT Professionals
http://microsoft.com/technet
Sessions on Demand
http://channel9.msdn.com/Events/TechEd
![Page 119: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/119.jpg)
Complete an evaluation and enter to win!
![Page 120: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/120.jpg)
Evaluate this session
Scan this QR code to evaluate this session.
![Page 121: C++ When do you need to go native to C, C with C#? Almost never if you are creating a new application, for which you have control to code every component](https://reader035.vdocument.in/reader035/viewer/2022081516/56649da65503460f94a9267b/html5/thumbnails/121.jpg)
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.