Advanced Programming & C++ Language

Similar documents
C++11 and Compiler Update

C The new standard

Miri Ben-Nissan (Kopel) (2017)

Modern and Lucid C++ Advanced for Professional Programmers. Part 3 Move Semantics. Department I - C Plus Plus Advanced

Introduction to Move Semantics in C++ C and C

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd.

COMP6771 Advanced C++ Programming

QUIZ. What is wrong with this code that uses default arguments?

The issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management

C++11/14 Rocks. Clang Edition. Alex Korban

Introduction to C++11 and its use inside Qt

Object-Oriented Programming for Scientific Computing

Tokens, Expressions and Control Structures

Instantiation of Template class

Advanced C++ Topics. Alexander Warg, 2017

COMP6771 Advanced C++ Programming

A Taxonomy of Expression Value Categories

Rvalue References & Move Semantics

Rvalue References, Move Semantics, Universal References

Fast Introduction to Object Oriented Programming and C++

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Overview. 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43

Short Notes of CS201

std::optional from Scratch

A Crash Course in (Some of) Modern C++

Database Systems on Modern CPU Architectures

Pointers. Developed By Ms. K.M.Sanghavi

CS201 - Introduction to Programming Glossary By

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

Basic Types, Variables, Literals, Constants

Objects Managing a Resource

Intermediate C++ 1/83

register lock_guard(mtx_); string_view s = register to_string(42); We propose register-expression to grant the temporary objects scope lifetimes.

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018

Introduction to C++ Systems Programming

COMP6771 Advanced C++ Programming

Object-Oriented Principles and Practice / C++

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers

use static size for this buffer

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

CS

CSE 333 Lecture smart pointers

Modernizing legacy C++ code

Domains: Move, Copy & Co

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

C++ Primer, Fifth Edition

Advanced Systems Programming

Implicit Evaluation of auto Variables and Arguments

Value categories. PRvalues. Lvalues

Rvalue References as Funny Lvalues

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Homework 4. Any questions?

Modern C++, From the Beginning to the Middle. Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017

Axivion Bauhaus Suite Technical Factsheet AUTOSAR

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University

Remedial C Now that we can actually use it Pete Williamson

Object-Oriented Principles and Practice / C++

Introduce C# as Object Oriented programming language. Explain, tokens,

A polymorphic value-type for C++

Smart Pointers. Some slides from Internet

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Ch. 12: Operator Overloading

Part X. Advanced C ++

CS3157: Advanced Programming. Outline

Chapter 2. Procedural Programming

Object-Oriented Principles and Practice / C++

04-19 Discussion Notes

CSCI-1200 Data Structures Spring 2017 Lecture 27 Garbage Collection & Smart Pointers

Chapter 15 - C++ As A "Better C"

Assertions and Exceptions

Overload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019

CPSC 427: Object-Oriented Programming

Introduction to C++ with content from

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Outline. 1 About the course

Let return Be Direct and explicit

void fun() C::C() // ctor try try try : member( ) catch (const E& e) { catch (const E& e) { catch (const E& e) {

Variables. Data Types.

CSE 333 Lecture smart pointers

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

C++ is Evolving. std::array

Auto - a necessary evil?

04-17 Discussion Notes

Exception Safe Coding

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Copyie Elesion from the C++11 mass. 9 Sep 2016 Pete Williamson

CE221 Programming in C++ Part 1 Introduction

CSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

ECE 449 OOP and Computer Simulation Lecture 12 Resource Management II

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

CS11 Advanced C++ Spring 2018 Lecture 2

I m sure you have been annoyed at least once by having to type out types like this:

Structured bindings with polymorphic lambas

Absolute C++ Walter Savitch

Transcription:

Advanced Programming & C++ Language ~10~ C++11 new features Ariel University 2018 Dr. Miri (Kopel) Ben-Nissan

2 Evolution of C++ Language

What is C++11? 3 C++11 is the ISO C++ standard formally ratified in August 2011. C++11 is a major upgrade over C++98/03, with performance and convenience features that make it feel like a new language. What is C++0x? The under-development name for C++11.

What is C++11? (Cont ) 4 C++ has from its inception been a generalpurpose programming language with a bias towards systems programming that is a better C supports data abstraction supports object-oriented programming supports generic programming

What is C++11? (Cont ) 5 The overall aims of the C++11 effort was to strengthen that: Make C++ a better language for systems programming and library building. Make C++ easier to teach and learn. Naturally, this is done under very stringent compatibility constraints.

(1) auto & decltype 6 A sort of placeholder for a type. The compiler will deduce the actual type of a variable that is being declared from its initializer.

auto & decltype (Cont ) 7 Using STL becomes much more simple: In C++11, auto cannot be used as a return type of a function. However, it is possible to return an auto type while using the decltype keyword.

8 auto & decltype (Cont )

9 auto & decltype (Cont )

10 auto & decltype (Cont )

auto & decltype (Cont ) 11 The decltype type specifier yields the type of a specified expression. Use auto and decltype to declare a template function whose return type depends on the types of its template arguments. In C++11, you can use the decltype type specifier on a trailing return type, together with the auto keyword, to declare a template function whose return type depends on the types of its template arguments.

(2) Lambdas 12 Lambdas are anonymous functions. It is a powerful feature borrowed from functional programming. A lambda function is a function that you can write inline in your source code (usually to pass in to another function, similar to the idea of a functor or function pointer).

Lambda - motivation 13 Example 1???

Lambda motivation (cont...) 14 Option 1: using a function object.

15 Function objects: class with constructor and single member operator() template <class T> class myfunc { public: myfunc( /*arguments save needed state info */ ) { } T operator() jbo cnuf rof sgra */(*/) { /* call some useful function with saved state info and args as its parameters */ } private: /* state info here */ }; Lambda motivation (cont...)

Lambda motivation (cont...) 16 Function Object

17 Lambda motivation (cont...)

Lambda motivation (cont...) 18 Option 2: using lambda expressions.

Lambdas (Cont...) 19 With Lambdas it is much easier: capture specification

20 Lambdas (Cont...)

Lambdas (Cont...) 21 In C++11, if the compiler can deduce the return value of the lambda function, it will do it rather than force you to include it.

Lambdas (Cont...) 22 Example 2

23 Lambdas (Cont...)

Lambdas (Cont...) 24 Example 3

Lambdas (Cont...) 25 Compilation error without the &.

(3) Constructor issues 26 default = the compiler will define the implicit default constructor even if other constructors are present.

Constructor issues (cont...) 27 delete = if this constructor is selected by overload resolution, the program fails to compile. The compiler will not generate this ctor for you. The "delete" mechanism can be used for any function.

Constructor issues (cont...) 28 Default values of member variables: since c++11 it is possible to give default values inside the class declaration:

Constructor issues (cont...) 29 An array of objects: What if we don t have a default constructor?

(4) Universal References 30 C++11 has introduced the concept of rvalue references (specified with &&) to differentiate a reference to an lvalue or an rvalue.

Universal References(Cont...) 31 If you can take the address of an expression, the expression is an lvalue. If the type of an expression is an lvalue reference (e.g., T& or const T&, etc.), that expression is an lvalue. Otherwise, the expression is an rvalue. Conceptually (and typically also in fact), rvalues correspond to temporary objects, such as those returned from functions or created through implicit type conversions. Most literal values (e.g., 10 and 5.3) are also rvalues.

32 Universal References(Cont...)

Universal References(Cont...) 33 An expression is an rvalue if it results in a temporary object.

Universal References(Cont...) 34 Prior to C++11, if you had a temporary object, you could use a "regular" or "lvalue reference" to bind it, but only if it was const: In C++11, however, there's a new kind of reference, an "r-value reference", that will let you bind a mutable reference to an r-value, but not an l-value. In other words, r-value references are perfect for detecting if a value is temporary object or not.

Universal References(Cont...) 35 Rvalue references use the && syntax instead of just &, and can be const and non-const, just like lvalue references.

Universal References(Cont...) 36 When using a template function, than it appears that the parameter T&& can capture either l-value and r-value expressions, that it is called Universal References.

Template Type Deduction in C++ 37 Suppose we have the following template function: template <class T> void f(paramtype param); f(param); The type T is depends on the type of param parameter sent to the function f.

Template Type Deduction in C++ (Cont...) 38 Reference Collapsing Rules: A& & becomes A& A& && becomes A& A&& & becomes A& A&& && becomes A&&

Template Type Deduction in C++ (Cont...) 39 Case 1: Passing param by reference/pointer If the passed argument is reference ignore it. Do pattern matching to deduce T. T type param s type int x=22; f(x); int int& const int cx = x; f(cx); int const int& const int& rx = x; f(rx); const int const int&

Template Type Deduction in C++ (Cont...) 40 T type param s type int x=22; f(x); int const int& const int cx = x; f(cx); int const int& const int& rx = x; f(rx); int const int&

Template Type Deduction in C++ (Cont...) 41 The same rules apply on auto reduction: int x=22; auto& v1 = x; const int cx = x; auto& v2 = cx; const int& rx = x; auto& v3 = rx; v s type int& const int& const int& auto type int const int const int

Template Type Deduction in C++ (Cont...) 42 Case 2: Universal References T&& can capture either l-value or r-value (templates only!!!). It depends if expr is l-value or r-value. If expr is l-value with deduced type E, T deduced as E&.

Template Type Deduction in C++ (Cont...) 43 Reference Collapsing Rules again: A& & becomes A& A& && becomes A& A&& & becomes A& A&& && becomes A&&

Template Type Deduction in C++ (Cont...) 44 int x=22; f(x); //x is l-value const int cx = x; f(cx); //cx is l-value const int& rx = x; f(rx); //rx is l-value f(22); //r-value T type int& const int& const int& int param s type int& const int& const int& int&&

Template Type Deduction in C++ (Cont...) 45 Case 3: By value If expr is &, than the reference is ignored. If expr is const or volatile, it is ignored. Deduce T. T type param s type int x=22; f(x); int int const int cx = x; f(cx); int int const int& rx = x; f(rx); int int

(5) Move Semantics 46 The move semantics allow modifying rvalues (previously considered immutable and indistinguishable from const T& types).

Move Semantics (cont...) 47 Suppose we have a CMyVector class: For this class we ll need to implement copy constructor, destructor and assignment operator.

48 Move Semantics (cont...)

Move Semantics (cont...) 49 Similar reasoning applies to the copy constructor. Now suppose CMyVector is used as follows:

Move Semantics (cont...) 50 The last line above clones the resource from the temporary returned by foo, destructs the resource held by x and replaces it with the clone, destructs the temporary and thereby releases its resource.

Move constructor and move assignment operator (Cont...) 51 #include <iostream.h> class MyString { public: MyString(const char* str=null); ~MyString(); private: char* m_str; };

52 Move constructor and move assignment operator (Cont...) MyString::MyString(const char* str1/*=null*/) { cout<<"creating a string\n"; if(str1){ m_str = new char[strlen(str1)+1]; strcpy(m_str,str1); } else{ m_str = NULL; } } MyString::~MyString() { if(m_str){ delete[] m_str; m_str = NULL; } cout<<"deleting a string\n"; }

Move constructor and move assignment operator (Cont...) MyString GetString() { MyString str2("testing"); return str2; } int main() { MyString str3( GetString() ); } main() GetString() str3 temp str2 53 m_str

Move Semantics (cont...) 54 Rather obviously, it would be ok, and much more efficient, to swap resource pointers (handles) between x and the temporary, and then let the temporary's destructor destruct x's original resource. In other words, in the special case where the right hand side of the assignment is an rvalue, we want the copy assignment operator to act like this: // [...] // swap m_parr and x.m_parr // [...]

55 Move Semantics (Cont...) Move semantics allows you to avoid unnecessary copies when working with temporary objects that are about to evaporate, and whose resources can safely be taken from that temporary object and used by another.

Example 1: l-value and r-value 56 דוגמא 1: העברת אובייקט לפונקציה.by value אם האובייקט שנשלח הוא l-value אזי: נבנה את הפרמטר עם.copy ctor אם האובייקט שנשלח הוא r-value אזי: נבנה את הפרמטר עם.move ctor

57 Example 2: l-value and r-value

Example 3: l-value and r-value 58 דוגמא 3: הפונקציה מקבלת את הפרמטר כ-.&& אם שלחנו לפונקציה -l,value אזי: שגיאת קומפילציה!! && לא יכול לקבל!l-value אם שלחנו לפונקציה,r-value אזי: נבנה את הפרמטר של הפונקציה עם ה- move.ctor error C2664: 'void foo(cclassc &&)': cannot convert argument 1 from 'CClassC' to 'CClassC &&' note: You cannot bind an lvalue to an rvalue reference

Example 4: l-value and r-value 59 דוגמא 4: הפונקציה מקבלת את הפרמטר.by reference אם שלחנו לפונקציה -l,value אזי: לא נקרא שום בנאי, כי העברנו.by reference אם שלחנו לפונקציה,r-value אזי: נבנה את הפרמטר של הפונקציה עם ה- move.ctor

60 Move constructor and move assignment operator (Cont...)

61 Move constructor and move assignment operator (Cont...)

62 Move constructor and move assignment operator (Cont...)

63 Move constructor and move assignment operator (Cont...)

Move constructor and move assignment operator (Cont...) 64 If no user-defined move constructors are provided for a class type (struct, class, or union), and all of the following is true: there are no user-declared copy constructors; there are no user-declared copy assignment operators; there are no user-declared move assignment operators; there are no user-declared destructors; then the compiler will declare a move constructor as a non-explicit inline public member of its class with the signature T::T(T&&).

65

66

(6) Perfect Forwarding 67 What will happen if from a template function that gets a universal reference, we want to pass the argument on to another function? Is it an l-value or an r-value?

68 perfect forwarding (cont...)

perfect forwarding (cont...) 69 Case 1: sending l-value to the template function:

perfect forwarding (cont...) 70 Case 2: sending r-value to the template function:

std:move 71 A casting expression from any type to an r-value. Compilation-time! It casts the l-value expression x of type X to an r- value expression of type X. move can also accept an rvalue.

std::forward 72 A conditional casting from any type to an r-value. Compilation time! If the expression is an l-value, that it won t be cast. If the expression is an r-value, that it will be casted to r-value.

Perfect forwarding (cont...) 73 If a template function gets a T object and wants to forward it to another function, we would like it to be done as efficient as possible. If the parameter is passed as an r-value, than we want it to also be passed as r-value, and not creating a new object from it. It will be done by declaring the type of argument as T&& and use the std::forward casting.

74 Perfect forwarding (cont...)

75 Perfect forwarding (cont...)

76 (7) non-member begin() and end()

non-member begin() and end() (Cont ( 77 With non-member begin() and end() it could be put as this:

(8) all_of, any_of and none_of 78 They check if the supplied unary predicate return true for all, any or no element in a range.

(9) nullptr 79 Zero used to be the value of null pointers, and that has drawbacks due to the implicit conversion to integral types. Oddly, in C++, the expression used, 0 (or NULL, always #defined to zero) was not even a pointer type.

80 nullptr (Cont ) In C++11, nullptr is a new keyword that can (and should!) be used to represent NULL pointers The keyword nullptr denotes a value of type std::nullptr_t that represents the null pointer literal. Implicit conversions exists from nullptr to null pointer value of any pointer type and any pointerto-member types, but also to bool (as false). But no implicit conversion to integral types exist. For backward compatibility 0 is still a valid null pointer value.

81 nullptr (Cont )

nullptr (Cont ) 82 nullptr is its own unique type, you can use it as a constructor or function argument when you want to be sure that you only ever take an empty pointer for a value.

83 nullptr (Cont )

(10) Range-based for loops 84 C++11 augmented the for statement to support the "foreach" paradigm of iterating over collections. In the new form, it is possible to iterate over C-like arrays, initializer lists and anything for which the non-member begin() and end() functions are overloaded. This for each for is useful when you just want to get and do something with the elements of a collection/array and don't care about indexes, iterators or number of elements.

85 Range-based for loops (Cont )

(11) Override and final 86 The virtual keyword is optional and that makes reading code a bit harder, because you may have to look through the top of the hierarchy to check if the method is virtual.

87 Override and final (Cont ) Two new special identifiers (not keywords) have been added: override, to indicate that a method is supposed to be an override of a virtual method in a base class, and final, to indicate that a derived class shall not override a virtual method.

88 Override and final (Cont ) When used in a virtual function declaration or definition, final ensures that the function is virtual and specifies that it may not be overridden by derived classes. When used in a class definition, final specifies that this class may not appear in the base-specifier-list of another class definition (in other words, cannot be derived from). final is an identifier with a special meaning when used in a member function declaration or class head. In other contexts it is not reserved and may be used to name objects and functions.

89 Override and final (Cont )

90 Override and final (Cont )

91 (12) Smart pointers Smart pointers with reference counting and auto releasing of owned memory that are available: unique_ptr: should be used when ownership of a memory resource does not have to be shared (it doesn't have a copy constructor), but it can be transferred to another unique_ptr (move constructor exists). shared_ptr: should be used when ownership of a memory resource should be shared (hence the name). weak_ptr: holds a reference to an object managed by a shared_ptr, but does not contribute to the reference count; it is used to break dependency cycles. On the other hand the auto_ptr is obsolete and should no longer be used.

92 Smart pointers (Cont...)

Smart pointers (Cont...) 93 p1 p2 p int = 42 p3

Smart pointers (Cont...) 94 make_shared<t> is a non-member function and has the advantage of allocating memory for the shared object and the smart pointer with a single allocation, as opposed to the explicit construction of a shared_ptr via the contructor, that requires at least two allocations. In addition to possible overhead, there can be situations where memory leaks can occur because of that.

Smart pointers (Cont...) 95 In the next example memory leaks could occur if seed() throws an error.

Smart pointers (Cont...) 96 std::weak_ptr is used when an object needs to be accessed only if it exists, and it may be deleted at any time by someone else. It is used to track the object, and it is converted to std::shared_ptr to assume temporary ownership. If the original std::shared_ptr is destroyed at this time, the object's lifetime is extended until the temporary std::shared_ptr is destroyed as well. You get a shared_ptr to the referred object by calling lock(), in order to access the object.

Smart pointers (Cont...) 97 If you try to lock on an expired weak_ptr (the object is weakly reference has been released) you get an empty shared_ptr.

Smart pointers (Cont...) 98 Note that it doesn t mean that we are not going to use regular pointers anymore. Raw pointers are bad when used for performing manual memory management, i.e. allocating and deallocating objects through new and delete. When used purely as a means to achieve reference semantics and pass around non-owning, observing pointers, there is nothing intrinsically dangerous in raw pointers, except maybe for the fact that one should take care not to dereference a dangling pointer.

(13) noexcept operator 99 The noexcept operator performs a compile-time check that returns true if an expression is declared to not throw any exceptions. It can be used within a function template's noexcept specifier to declare that the function will throw exceptions for some types but not others.

noexcept operator (cont...) 100 The noexcept operator does not evaluate expression. The result is false if the expression contains at least one of the following potentially evaluated constructs: call to any type of function that does not have non-throwing exception specification, unless it is a constant expression. throw expression. dynamic_cast expression when the target type is a reference type, and conversion needs a run time check typeid expression when argument type is polymorphic class type In all other cases the result is true. Since C++17: The result is true if the set of potential exceptions of the expression is empty, and false otherwise.

noexcept operator (cont...) 101 #include <iostream> #include <utility> #include <vector> void may_throw(); void no_throw() noexcept; auto lmay_throw = []{}; auto lno_throw = []() noexcept {};

noexcept operator (cont...) 102 class T{ public: ~T(){} // dtor prevents move ctor // copy ctor is noexcept }; class U{ public: ~U(){} // dtor prevents move ctor // copy ctor is noexcept(false) std::vector<int> v; }; class V{ public: std::vector<int> v; };

noexcept operator (cont...) 103 int main() { T t; U u; V v; std::cout << std::boolalpha << "Is may_throw() noexcept? " << noexcept(may_throw()) << '\n ; std::cout << "Is no_throw() noexcept? " << noexcept(no_throw()) << '\n ; std::cout << "Is lmay_throw() noexcept? " << noexcept(lmay_throw()) << '\n ;

noexcept operator (cont...) 104 std::cout << "Is lno_throw() noexcept? " << noexcept(lno_throw()) << '\n ; std::cout << "Is ~T() noexcept? " << noexcept(std::declval<t>().~t()) << '\n ; // note: the following tests also require // that ~T() is noexcept because the // expression within noexcept constructs and // destroys a temporary std::cout << "Is T(rvalue T) noexcept? " << noexcept(t(std::declval<t>())) << '\n ;

noexcept operator (cont...) 105 std::cout << "Is T(lvalue T) noexcept? " << noexcept(t(t)) << '\n ; std::cout << "Is U(rvalue U) noexcept? " << noexcept(u(std::declval<u>())) << '\n ; std::cout << "Is U(lvalue U) noexcept? " << noexcept(u(u(( << \n ; std::cout << "Is V(rvalue V) noexcept? " << noexcept(v(std::declval<v>())) << '\n ; std::cout << "Is V(lvalue V) noexcept? " << noexcept(v(v)) << '\n'; }

(14) Strongly-typed enums 106 History of enums in C and C++:

Strongly-typed enums (Cont ) 107 In version2 the definition of E is independent of interface.h but it is syntax error

108 Strongly-typed enums (Cont ) "Traditional" enums in C++ have some drawbacks: they export their enumerators in the surrounding scope (which can lead to name collisions), they are implicitly converted to integral types cannot have a user-specified underlying type. C++ 11 introduces a new category of enums, called strongly-typed enums and the enum class keywords. They no longer export their enumerators in the surrounding scope, are no longer implicitly converted to integral types can have a user-specified underlying type

Strongly-typed enums (Cont ) 109 What if I need const char?

Strongly-typed enums (Cont ) 110 A final advantage of enum classes is that you can set the size of your enum--you can use any signed or unsigned integer type. It defaults to int, but you can also use char, unsigned long, etc. This will ensure some measure of compatibility across compilers.

111 Strongly-typed enums (Cont )

Strongly-typed enums (Cont ) 112 The use of the word class is meant to indicate that each enum type really is different and not comparable to other enum types. Strongly typed enums, enum classes, also have better scoping. Each enum value is scoped within the name of the enum class.

Strongly-typed enums (Cont ) 113 Forward declaration rules for scoped and unscoped enums:

114 Strongly-typed enums (Cont ) One problem that C++ has suffered from is a lack of standard types that provide fixed, well-defined sizes. For example, sometimes you want to have a 32-bit integer, not just an int that might have different sizes on different architectures. In C++11, the C99 header file stdint.h has been included as cstdint. The cstdint header includes types such as std::int8_t, std::int16_t, std::int32_t, and std::int64_t (as well as unsigned versions that begin with u: std::uint8_t).

Useful Links for C++11 & 14 115 Ten C++11 Features Every C++ Developer Should Use C++0x: The future of C++ Scott Meyers great lecture on effective modern c++