Advanced Programming & C++ Language

Size: px
Start display at page:

Download "Advanced Programming & C++ Language"

Transcription

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

2 2 Evolution of C++ Language

3 What is C++11? 3 C++11 is the ISO C++ standard formally ratified in August 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.

4 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

5 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.

6 (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.

7 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 8 auto & decltype (Cont )

9 9 auto & decltype (Cont )

10 10 auto & decltype (Cont )

11 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.

12 (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).

13 Lambda - motivation 13 Example 1???

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

15 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...)

16 Lambda motivation (cont...) 16 Function Object

17 17 Lambda motivation (cont...)

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

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

20 20 Lambdas (Cont...)

21 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.

22 Lambdas (Cont...) 22 Example 2

23 23 Lambdas (Cont...)

24 Lambdas (Cont...) 24 Example 3

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

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

27 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.

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

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

30 (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.

31 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 32 Universal References(Cont...)

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

34 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.

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

36 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.

37 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.

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

39 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&

40 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&

41 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

42 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&.

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

44 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&&

45 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

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

47 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 48 Move Semantics (cont...)

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

50 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.

51 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 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"; }

53 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

54 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 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.

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

57 57 Example 2: l-value and r-value

58 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

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

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

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

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

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

64 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 65

66 66

67 (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 68 perfect forwarding (cont...)

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

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

71 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.

72 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.

73 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 74 Perfect forwarding (cont...)

75 75 Perfect forwarding (cont...)

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

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

78 (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.

79 (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 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 81 nullptr (Cont )

82 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 83 nullptr (Cont )

84 (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 85 Range-based for loops (Cont )

86 (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 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 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 89 Override and final (Cont )

90 90 Override and final (Cont )

91 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 92 Smart pointers (Cont...)

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

94 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.

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

96 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.

97 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.

98 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.

99 (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.

100 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.

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

102 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; };

103 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 ;

104 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 ;

105 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'; }

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

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

108 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

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

110 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 111 Strongly-typed enums (Cont )

112 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.

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

114 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).

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

C++11 and Compiler Update

C++11 and Compiler Update C++11 and Compiler Update John JT Thomas Sr. Director Application Developer Products About this Session A Brief History Features of C++11 you should be using now Questions 2 Bjarne Stroustrup C with Objects

More information

C The new standard

C The new standard C++11 - The new standard Lars Kühne Institut für Informatik Lehrstuhl für theoretische Informatik II Friedrich-Schiller-Universität Jena January 16, 2013 Overview A little bit of history: C++ was initially

More information

Miri Ben-Nissan (Kopel) (2017)

Miri Ben-Nissan (Kopel) (2017) Miri Ben-Nissan (Kopel) (2017) int attributes set of operations Attributes: 4 bytes. Integer numbers. Operations: numerical operators logical operations bit operations I/O operations Data Types define

More information

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

Modern and Lucid C++ Advanced for Professional Programmers. Part 3 Move Semantics. Department I - C Plus Plus Advanced Department I - C Plus Plus Advanced Modern and Lucid C++ Advanced for Professional Programmers Part 3 Move Semantics Thomas Corbat / Prof. Peter Sommerlad Rapperswil, 09.03.2018 HS2018 Move Semantics 2

More information

Introduction to Move Semantics in C++ C and C

Introduction to Move Semantics in C++ C and C Introduction to Move Semantics in C++ C++ 2011 and C++ 2014 Jean-Paul RIGAULT University of Nice - Sophia Antipolis Engineering School Computer Science Department Sophia Antipolis, France Contents of the

More information

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

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd. C++11: 10 Features You Should be Using Gordon Brown @AerialMantis R&D Runtime Engineer Codeplay Software Ltd. Agenda Default and Deleted Methods Static Assertions Delegated and Inherited Constructors Null

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.. COMP6771 Advanced C++ Programming Week 5 Part Two: Dynamic Memory Management 2016 www.cse.unsw.edu.au/ cs6771 2.. Revisited 1 #include 2 3 struct X { 4 X() { std::cout

More information

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

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

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

The issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management Session 8 Memory Management The issues Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Programs manipulate data, which must be stored

More information

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

C++11/14 Rocks. Clang Edition. Alex Korban C++11/14 Rocks Clang Edition Alex Korban 1 Contents Introduction 9 C++11 guiding principles... 9 Type Inference 11 auto... 11 Some things are still manual... 12 More than syntactic sugar... 12 Why else

More information

Introduction to C++11 and its use inside Qt

Introduction to C++11 and its use inside Qt Introduction to C++11 and its use inside Qt Olivier Goffart February 2013 1/43 Introduction to C++11 and its use inside Qt About Me http://woboq.com http://code.woboq.org 2/43 Introduction to C++11 and

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing Smart Pointers and Constness Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de Summer

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

Advanced C++ Topics. Alexander Warg, 2017

Advanced C++ Topics. Alexander Warg, 2017 www.kernkonzept.com Advanced C++ Topics Alexander Warg, 2017 M I C R O K E R N E L M A D E I N G E R M A N Y Overview WHAT IS BEHIND C++ Language Magics Object Life Time Object Memory Layout INTRODUCTION

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1. COMP6771 Advanced C++ Programming Week 4 Part One: (continued) and 2016 www.cse.unsw.edu.au/ cs6771 2. Inline Constructors, Accessors and Mutators Question (from 2015): In the week 3 examples, constructors

More information

A Taxonomy of Expression Value Categories

A Taxonomy of Expression Value Categories Document: Author: Date: 2010-03-12 Revision: 6 PL22.16/10-0045 = WG21 N3055 William M. Miller Edison Design Group A Taxonomy of Expression Value Categories Revision History: Revision 6 (PL22.16/10-0045

More information

Rvalue References & Move Semantics

Rvalue References & Move Semantics Rvalue References & Move Semantics PB173 Programming in Modern C++ Nikola Beneš, Vladimír Štill, Jiří Weiser Faculty of Informatics, Masaryk University spring 2016 PB173 Modern C++: Rvalue References &

More information

Rvalue References, Move Semantics, Universal References

Rvalue References, Move Semantics, Universal References Rvalue References, Move Semantics, Universal References PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill Faculty of Informatics, Masaryk University Spring 2018 PV264: Rvalue References,

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

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

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

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

Overview. 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43 Advanced C++ 1/43 Overview 1. Expression Value Categories 2. Rvalue References 3. Templates 4. Miscellaneous Hilarity 2/43 1. Expression Value Categories These are not the droids you re looking for ~Obi-wan

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

std::optional from Scratch

std::optional from Scratch std::optional from Scratch https://wg21.link/n4606 http://en.cppreference.com/w/cpp/utility/optional http://codereview.stackexchange.com/questions/127498/an-optionalt-implementation An optional object

More information

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

A Crash Course in (Some of) Modern C++ CMPT 373 Software Development Methods A Crash Course in (Some of) Modern C++ Nick Sumner wsumner@sfu.ca With material from Bjarne Stroustrup & Herb Sutter C++ was complicated/intimidating Pointers Arithmetic

More information

Database Systems on Modern CPU Architectures

Database Systems on Modern CPU Architectures Database Systems on Modern CPU Architectures Introduction to Modern C++ Moritz Sichert Technische Universität München Department of Informatics Chair of Data Science and Engineering Overview Prerequisites:

More information

Pointers. Developed By Ms. K.M.Sanghavi

Pointers. Developed By Ms. K.M.Sanghavi Pointers Developed By Ms. K.M.Sanghavi Memory Management : Dynamic Pointers Linked List Example Smart Pointers Auto Pointer Unique Pointer Shared Pointer Weak Pointer Memory Management In order to create

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

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

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011 More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors

More information

Basic Types, Variables, Literals, Constants

Basic Types, Variables, Literals, Constants Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic

More information

Objects Managing a Resource

Objects Managing a Resource Objects Managing a Resource 1 What is a Resource Respects Release/Acquire protocol files (open/close) memory allocation (allocate/free) locks (acquire/release). 2 What is a Resource Objects when constructed,

More information

Intermediate C++ 1/83

Intermediate C++ 1/83 Intermediate C++ 1/83 Sections I. Memory Management Basics II. The C++ Standard Library III. Casting IV. Resource Management: RAII 2/83 I. Memory Management Basics 1. Checking for memory leaks 2. Pass

More information

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

register lock_guard(mtx_); string_view s = register to_string(42); We propose register-expression to grant the temporary objects scope lifetimes. Doc. no. P0577R0 Date 2017-02-02 Reply-to Zhihao Yuan < zy@miator.net > Audience Evolution Working Group Keep that Temporary! Motivation Introduction Design Decisions What It Is Register expression is

More information

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

Overload Resolution. Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018 Ansel Sermersheim & Barbara Geller ACCU / C++ June 2018 1 Introduction Definition of Function Overloading Determining which Overload to call How Overload Resolution Works Standard Conversion Sequences

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

COMP6771 Advanced C++ Programming

COMP6771 Advanced C++ Programming 1.... COMP6771 Advanced C++ Programming Week 5 Part One: Exception Handling 2016 www.cse.unsw.edu.au/ cs6771 2.... Memory Management & Exception Handling.1 Part I: Exception Handling Exception objects

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer September 26, 2016 OOPP / C++ Lecture 4... 1/33 Global vs. Class Static Parameters Move Semantics OOPP / C++ Lecture 4... 2/33 Global Functions

More information

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

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()

More information

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

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak! //Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new

More information

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

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual

More information

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

CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers Review from Lecture 23 Basic exception mechanisms: try/throw/catch Functions & exceptions, constructors & exceptions Today

More information

use static size for this buffer

use static size for this buffer Software Design (C++) 4. Templates and standard library (STL) Juha Vihavainen University of Helsinki Overview Introduction to templates (generics) std::vector again templates: specialization by code generation

More information

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

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public

More information

CS

CS CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia New exercise out today, due Wednesday morning Exam Friday

More information

Modernizing legacy C++ code

Modernizing legacy C++ code Modernizing legacy C++ code Marius Bancila mariusbancila marius.bancila Agenda Short intro Legacy and modernization Good practices Q&A Containers Resource management correctness Const correctness Type

More information

Domains: Move, Copy & Co

Domains: Move, Copy & Co 1 (20) Domains: Move, Copy & Co School of Engineering Sciences Program construction in C++ for Scientific Computing 2 (20) Outline 1 2 3 4 5 3 (20) What Do We Already Have A class hierarchy for constructing

More information

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors

Arrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8

More information

C++ Primer, Fifth Edition

C++ Primer, Fifth Edition C++ Primer, Fifth Edition Stanley B. Lippman Josée Lajoie Barbara E. Moo Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sidney Tokyo

More information

Advanced Systems Programming

Advanced Systems Programming Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short

More information

Implicit Evaluation of auto Variables and Arguments

Implicit Evaluation of auto Variables and Arguments Implicit Evaluation of auto Variables and Arguments Document number: N3748 Authors: Joël Falcou University Paris XI, LRI Peter Gottschling SimuNova Herb Sutter Microsoft Date: 2013-08-30 Project: Programming

More information

Value categories. PRvalues. Lvalues

Value categories. PRvalues. Lvalues Value categories v5 Every C++14 expression belongs to exactly one of the following classifications, known as value categories: lvalue, xvalue, prvalue. There's an overlap between these, so a higher level

More information

Rvalue References as Funny Lvalues

Rvalue References as Funny Lvalues I. Background Document: Author: Date: 2009-11-09 Revision: 1 PL22.16/09-0200 = WG21 N3010 William M. Miller Edison Design Group Rvalue References as Funny Lvalues Rvalue references were introduced into

More information

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

Homework 4. Any questions?

Homework 4. Any questions? CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible

More information

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

Modern C++, From the Beginning to the Middle. Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017 Modern C++, From the Beginning to the Middle Ansel Sermersheim & Barbara Geller ACCU / C++ November 2017 1 Introduction Where is the Beginning Data Types References Const Const Const Semantics Templates

More information

Axivion Bauhaus Suite Technical Factsheet AUTOSAR

Axivion Bauhaus Suite Technical Factsheet AUTOSAR Version 6.9.1 upwards Axivion Bauhaus Suite Technical Factsheet AUTOSAR Version 6.9.1 upwards Contents 1. C++... 2 1. Autosar C++14 Guidelines (AUTOSAR 17.03)... 2 2. Autosar C++14 Guidelines (AUTOSAR

More information

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

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University Polymorphism Miri Ben-Nissan (Kopel) 1 Shape Triangle Rectangle Circle int main( ) Shape* p = GetShape( ); p->draw( ); Shape* GetShape( ) choose randomly which shape to send back For example: Shape* p

More information

Remedial C Now that we can actually use it Pete Williamson

Remedial C Now that we can actually use it Pete Williamson Remedial C++ 11 Now that we can actually use it Pete Williamson (petewil00@hotmail.com) Overview (1) auto lambdas nullptr = default, = delete shared_ptr Range based for loops Overview (2) Uniform initialization

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer October 10, 2016 OOPP / C++ Lecture 7... 1/15 Construction and Destruction Kinds of Constructors Move Semantics OOPP / C++ Lecture 7... 2/15

More information

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

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

A polymorphic value-type for C++

A polymorphic value-type for C++ A polymorphic value-type for C++ ISO/IEC JTC1 SC22 WG21 Programming Language C++ P0201R2 Working Group: Library Evolution Date: 2017-10-16 Jonathan Coe Sean Parent

More information

Smart Pointers. Some slides from Internet

Smart Pointers. Some slides from Internet Smart Pointers Some slides from Internet 1 Part I: Concept Reference: Using C++11 s Smart Pointers, David Kieras, EECS Department, University of Michigan C++ Primer, Stanley B. Lippman, Jesee Lajoie, Barbara

More information

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

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

Part X. Advanced C ++

Part X. Advanced C ++ Part X Advanced C ++ topics Philip Blakely (LSC) Advanced C++ 158 / 217 References The following are highly regarded books. They are fairly in-depth, and I haven t read them in their entirity. However,

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer May 13, 2013 OOPP / C++ Lecture 7... 1/27 Construction and Destruction Allocation and Deallocation Move Semantics Template Classes Example:

More information

04-19 Discussion Notes

04-19 Discussion Notes 04-19 Discussion Notes PIC 10B Spring 2018 1 Constructors and Destructors 1.1 Copy Constructor The copy constructor should copy data. However, it s not this simple, and we need to make a distinction here

More information

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

CSCI-1200 Data Structures Spring 2017 Lecture 27 Garbage Collection & Smart Pointers CSCI-1200 Data Structures Spring 2017 Lecture 27 Garbage Collection & Smart Pointers Announcements Please fill out your course evaluations! Those of you interested in becoming an undergraduate mentor for

More information

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

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

Assertions and Exceptions

Assertions and Exceptions CS 247: Software Engineering Principles Assertions and Exceptions Reading: Eckel, Vol. 2 Ch. 1 Exception Handling U Waterloo CS247 (Spring 2017) p.1/32 Defensive Programming The question isn t whether

More information

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

Overload Resolution. Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019 Ansel Sermersheim & Barbara Geller Amsterdam C++ Group March 2019 1 Introduction Prologue Definition of Function Overloading Determining which Overload to call How Works Standard Conversion Sequences Examples

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 11 October 3, 2018 CPSC 427, Lecture 11, October 3, 2018 1/24 Copying and Assignment Custody of Objects Move Semantics CPSC 427, Lecture

More information

Introduction to C++ with content from

Introduction to C++ with content from Introduction to C++ with content from www.cplusplus.com 2 Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup

More information

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

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

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

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance

More information

Outline. 1 About the course

Outline. 1 About the course Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1

More information

Let return Be Direct and explicit

Let return Be Direct and explicit Document #: N4029 Date: 2014-05-23 Reply to: Herb Sutter hsutter@microsoft.com Let return Be Direct and explicit Herb Sutter This paper addresses EWG issue #114. Discussion C++ already recognizes that

More information

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

void fun() C::C() // ctor try try try : member( ) catch (const E& e) { catch (const E& e) { catch (const E& e) { TDDD38 APiC++ Exception Handling 134 Exception handling provides a way to transfer control and information from a point in the execution to an exception handler a handler can be invoked by a throw expression

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

CSE 333 Lecture smart pointers

CSE 333 Lecture smart pointers CSE 333 Lecture 14 -- smart pointers Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia Midterm Friday - Review in sections this week - Closed book; topic list

More information

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

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,

More information

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/35 ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review Professor Jia Wang Department of Electrical

More information

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010 CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)

More information

C++ is Evolving. std::array

C++ is Evolving. std::array C++ is Evolving C++ is an evolving language. A committee of the ISO (International Organization for Standards) ratifies proposed changes to C++. New standards have been released every few years. In this

More information

Auto - a necessary evil?

Auto - a necessary evil? Auto - a necessary evil? Roger Orr OR/2 Limited ACCU 2013 auto is new in C++11 It has been under discussion for a while, as we shall see Some compilers added support for it early in C++0x so it has had

More information

04-17 Discussion Notes

04-17 Discussion Notes 04-17 Discussion Notes PIC 10B Spring 2018 1 RAII RAII is an acronym for the idiom Resource Acquisition is Initialization. What is meant by resource acquisition is initialization is that a resource should

More information

Exception Safe Coding

Exception Safe Coding Exception Safe Coding Dirk Hutter hutter@compeng.uni-frankfurt.de Prof. Dr. Volker Lindenstruth FIAS Frankfurt Institute for Advanced Studies Goethe-Universität Frankfurt am Main, Germany http://compeng.uni-frankfurt.de

More information

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

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language Introduction C++ widely-used general-purpose programming language procedural and object-oriented support strong support created by Bjarne Stroustrup starting in 1979 based on C Introduction to C++ also

More information

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

Copyie Elesion from the C++11 mass. 9 Sep 2016 Pete Williamson Copyie Elesion from the C++11 mass 9 Sep 2016 Pete Williamson C++ 11 is a whole new language Links to learning more: http://en.cppreference.com/w/cpp/language/copy_elision https://engdoc.corp.google.com/eng/doc/devguide/cpp/cpp11.shtml?cl=head

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

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

CSE 333. Lecture 11 - constructor insanity. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington CSE 333 Lecture 11 - constructor insanity Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington Administrivia Exercises: - New exercise out today, due Monday morning

More information

ECE 449 OOP and Computer Simulation Lecture 12 Resource Management II

ECE 449 OOP and Computer Simulation Lecture 12 Resource Management II ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/62 ECE 449 OOP and Computer Simulation Lecture 12 Resource Management II Professor Jia Wang Department of Electrical

More information

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

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

CS11 Advanced C++ Spring 2018 Lecture 2

CS11 Advanced C++ Spring 2018 Lecture 2 CS11 Advanced C++ Spring 2018 Lecture 2 Lab 2: Completing the Vector Last week, got the basic functionality of our Vector template working It is still missing some critical functionality Iterators are

More information

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

I m sure you have been annoyed at least once by having to type out types like this: Type Inference The first thing I m going to talk about is type inference. C++11 provides mechanisms which make the compiler deduce the types of expressions. These features allow you to make your code more

More information

Structured bindings with polymorphic lambas

Structured bindings with polymorphic lambas 1 Introduction Structured bindings with polymorphic lambas Aaryaman Sagar (aary800@gmail.com) August 14, 2017 This paper proposes usage of structured bindings with polymorphic lambdas, adding them to another

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information