C++11 Introduction to the New Standard. Alejandro Cabrera February 1, 2012 Florida State University Department of Computer Science
|
|
- Felicia Thornton
- 6 years ago
- Views:
Transcription
1 C++11 Introduction to the New Standard Alejandro Cabrera February 1, 2012 Florida State University Department of Computer Science
2 Overview A Brief History of C++ Features Improving: Overall Use Meta-programming Resource-critical/High-performance Programming Class and Object-Oriented Design New Libraries How to Use it Today
3 A Brief History C With Classes C++ v2.0 C++98 Boost C++ Libraries C++03 and C++TR1 C++11
4 C With Classes (1979) Started as a result of Ph.D. thesis work of Bjarne Stroustrup Added to C: Classes Derived classes Strong type checking Inlining Default function arguments
5 C++ v 1.0 (1983) Added to C With Classes: Virtual functions Function name and operator overloading References Constants User-controlled, free-store memory control Improved type checking Single-line comments The C++ Programming Language 1e published (1985)
6 C++ v 2.0 (1989) The C++ Programming Language 2e published (1991) Added to C++ v 1.0: Multiple inheritance Abstract classes Static member functions const member functions Protected members Late additions: Templates Exceptions Namespaces New-style casts Boolean type
7 C++ 98 (1998) C++ is standardized (ISO/IEC 14882:1998) Standard includes language core and standard library Standard library includes C library, containers, I/O streams, and much more
8 Boost C++ Libraries (199x) The Boost C++ libraries provide portable, efficient implementations of many C++ library components Often times, libraries that appear in later standards make their debut in Boost Boost releases go back as far as 1999 For more information, visit:
9 C++ 03 (2003) Correction to C++ standard is published (ISO/IEC 14882:2003) TR1, an extension to the standard library, was also published around this time (2005) TR1 is only a draft, not a standard Most features detailed in TR1 became part of 2011 standard
10 C++ 11 (2011) Unanimously approved by C++ committee in August 2011 C++11 brings many new features, many that make it more apparent that C++ is a hybrid language This presentation will cover most of the new features in detail
11 History Summary Early C C++, first standard 1998 Birth of Boost C++ Libraries C++, corrected standard 2003 C++ TR C C++ TR2 W.I.P.
12 Features Overview Easier programming Easier meta-programming Facilitated, performance-critical programming Better class design
13 C++11 introduces: new keywords new constructs Easier Programming Introduction fixes parsing issues adds support for garbage collection I'll demonstrate how this leads to easier programming
14 Easier Programming auto keyword auto is not a new keyword in C++ auto used to declare a given variable as a local variable Now, auto is used to have the compiler perform type-inference for you
15 Uses of auto: Easier Programming auto keyword Simplify iterator use in iteration constructs Simplify type declarations in meta-programming contexts For more examples, refer to: auto.cpp auto also meshes well with the new range-for loop!
16 Easier Programming enum class Old-style enumerations have three problems: they implicitly covert to integers they are globally visible, introducing name-clashing the underlying type cannot be declared: introducing compatibility problems cannot be forward declared
17 Easier Programming enum class While old-style enums are still supported, newstyle enums address all their weaknesses: Using an enum class variable where an integer is expected raises a compiler error: Explicit cast required Scope of enum class declaration is limited to scope of declaration Underlying type can be specified For examples, refer to: enum_class.cpp
18 Easier Programming constexpr keyword For initializing complicated constants, sometimes functions are desired For example, initializing the size of a static buffer that depends on: Number of CPUs available on system Amount of memory available on system Speed of CPUs on system Maximum stack-size on system However, functions cannot be used to accomplish this in C or C++ - macros must be used Macros are not type-safe
19 Easier Programming constexpr keyword Introducing constexpr: Used to provide compile-time expressions Can be used with user-defined types Guarantees initialization at compile-time Used as a function qualifier before the function's return type Also allows for more extensive compileroptimization opportunities! For more details, refer to: constexpr.cpp
20 Easier Programming nullptr keyword Minor syntactic sugar improvement Previous efforts to define a clear use of null revolved around macros #define NULL ((void *) 0) Now, nullptr can be used to express null-pointer initialization where that is the intent. For more details, refer to: nullptr.cpp
21 Easier Programming range-for Loop Construct Major syntactic sugar upgrade Provides a for loop similar to for-each loop provided in other high-level languages Can be used on any sequence for which a begin() and end() function are defined! Especially useful for sequential one-pass algorithms and function applications For more details, refer to: rangefor.cpp
22 Easier Programming Initializer Lists Initializer lists allow the construction of any type using a curly-brace enclosed, comma-separated list of elements Previously, this style of construction was limited to primitive arrays with unspecified size Especially useful for providing easier to use interfaces for container types Critical for the support of a new feature, unified initialization For more details, refer to: ilist.cpp
23 Easier Programming Unified Initialization Currently, there are many ways to initialize C: X a = {v}; // structs, arrays X a = v; // primitives C++: new X(v); // heap allocation X a(v); // for classes with constructors X(v); // temporaries X(v); // functional-style casts
24 Easier Programming Unified Initialization The problem is, looking at a huge code base, it's impossible to tell just by looking if X(v) is a casting operation or a construction Solution: unified initialization X v{1, 2, 3}; vector<int> vec{1,2,3,4}; float *f{new float[10]}; int three{3}; ShadingMode shade{shadingmode::smooth}; For more details, refer to: unified_initialization.cpp
25 Easier Programming Right-Angle Bracket Parse Fix C++98/03 syntax specification did not account for: vector<vector<int>> x; Frequently, this was interpreted as either a right shift operation or input operator C++98/03 solution: vector<vector<int> > x; // space them out C++11 fixes this. An example is provided: right_bracket_parse.cpp
26 Easier Programming Improved POD Rules POD: Plain Old Data type, a.k.a., standard layout types Allows an object to be initialized using memcpy, and serialized/loaded using read/write directly An important concept for serialization and optimization C++98/03 only considered objects avoiding use of certain language features PODs Cannot use virtual functions Cannot have constructor/destructor Cannot allocate memory on heap
27 Easier Programming Improved POD Rules C++11 expands set of objects considered PODs: Recursively, if all members are PODs, so is the whole No virtual functions No virtual bases No references No multiple access specifiers (protected, public, private) The biggest addition is that POD types may now have constructors/destructors For more details, refer to: improved_pod.cpp Similar improvements have been made for unions!
28 Easier Programming Long Longs Guarantees availability of [unsigned] long long type See long_long.cpp
29 Easier Programming User-Defined Literals Various literal types have built-in support 12 // int 'a' // char as // null-terminated string 1.2f // float 1.2lf // double 0xD0 // hexadecimal However, there is no support for literals of user-defined types 123s // seconds? hello! s // std::string
30 Easier Programming User-Defined Literals C++11 introduces literal operators to create user-defined literals By overloading a single function, one can create literals with a given suffix for: integers floats strings characters
31 Easier Programming User-Defined Literals This is extremely useful for creating Domain- Specific Languages (DSLs), or say, implementing a unit system 25.1s // seconds 12.5mps // meters per seconds Distance m = 12.5mps * 25.1s For more details, refer to: user_defined_literals.cpp Requires GCC 4.7 (svn trunk, unreleased)
32 Easier Programming Raw Strings C++98 provides no means to escape strings for use with regular expression engines Language escaping rules get in the way of correctly writing regular expressions Example: match all lines containing two words separated by a backslash Solution: \\w\\\\\\w C++11 makes this much easier by providing raw strings.
33 Easier Programming Raw Strings Again, with raw strings: Solution: R (\w\\\w) More examples: Quoted string: R ( quoted string ) Regex: R ([\d\d\d]{3}) Even the delimiter pair () is only a default: Parenthetical string: R *( (Tough cookie.) )* Delimiter string is this color to ease reading For more examples, see: raw_strings.cpp
34 Easier Programming Lambda Functions In C++, to work with the standard algorithms library, one often had to create function objects For example, to count all elements less than 5: 1. Create a function object LessThan returns true if an input argument is less than 5 2.Pass LessThan to count_if as the final parameter.
35 Easier Programming Lambda Functions This has a few undesirable consequences LessThan potentially pollutes the global namespace Furthermore, function objects created at non-global scope cannot be used as template arguments To implement simple logic, an entire class had to be implemented (~5 LOC for easy cases) Lambdas were created to address these problems
36 Easier Programming Lambda Functions Lambdas are anonymous, shorthand function objects Note: C++11 did not invent lambdas. They appear in many modern languages, including: Haskell, Python, C#,
37 Easier Programming Structure of Lambda Functions C++11 lambdas have a structure that takes some getting used to The capture list (optionally) The argument list [same as function argument list] The function body (optionally) The return type using suffix return type syntax Only if the return type cannot be deduced, which is true most of the time for function bodies longer than a single statement
38 Easier Programming Lambda Functions: Capture List It can take on a few forms: [] take none of the variables from the enclosing scope [&] take all the variables from the enclosing scope by reference [=] take all the variables from the enclosing scope by value There is also support for capture-by-name, to capture only part of the enclosing scope
39 Easier Programming Lambda Functions: Return Type C++11 introduces a new way to specify return types that apply for the decltype keyword and for lambdas: suffix return style In a simple lambda, it looks like: [] (int a, int b) -> bool { return a < b; } For many examples, refer to: lambda.cpp
40 Benefits: Easier Programming Lambda Functions: Advice Concise, terse Does not pollute namespace Great for one- or two-liners Cons: Less readable intent may not be clear Can easily create obfuscated code! Capturing entire enclosing scope by value can be very expensive be careful! Keep in mind that C++11 now allows local-types as template arguments A local, function object class may be the best solution!
41 Easier Programming Generalized Attributes Crafted as an attempt to unify various compilerspecific extensions Generalized attributes will not be discussed further in this presentation, as support is nearly non-existent For further information: Generalized Attributes ISO/IEC Paper
42 Easier Programming Garbage Collection Garbage collection serves as a means to automatically clean up heap memory that cannot be reached Support for this has been experimental for a long time in C/C++ The standard now makes provisions for adding support if a compiler wishes to implement garbage collection For more details, see: GC ISO/IEC Paper
43 New keywords Easier Programming Summary auto, enum class, constexpr, nullptr New constructs range for-loop, initializer lists, unified initialization Language fixes Right-angle bracket parse Improved usability Less restrictive unions and PODs, long longs, user-defined literals, raw strings, lambdas, generalized attributes, enum class, local types as template args Support for garbage collection
44 Easier Meta-programming Introduction Meta-programming and related techniques allow for entire libraries of highly-optimized, highly-customizable software to be generated from a limited source base Meta-programming also adds new ways to compose classes and functions C++11 adds a few features to facilitate metaprogramming
45 decltype constexpr Easier Meta-programming Overview static_assert variadic templates <type_traits> library
46 Easier Meta-programming decltype keyword decltype used in conjunction with the new return type syntax can facilitate template programs Consider: template <class T, class U>??? mul(t x, U y) { } return x * y; What is the return type? (assuming operator*(x,y) is defined)
47 Easier Meta-programming decltype keyword Here is the solution using C++11: template <class T, class U> auto (T x, U y) -> decltype(x*y) { } return x * y; decltype expressions are evaluated at compile-time No examples are provided for decltype
48 Easier Meta-programming static_assert keyword static_assert is extremely valuable for placing compile-time constraints on templateparameters For example, in combination with the new type_traits library, one could...: Allow only integral parameters using is_integer Allow only values of N less than 16 for Factorial<N> Allow only POD types for MakePacket<PType> For an example, refer to: static_assert.cpp
49 Easier Meta-programming Variadic Templates One of the features behind some of the most amazing wizardry that goes on in metatemplate programming Previously, recursive template instantiation was required to emulate type-lists Could get very expensive for compiler Variadic templates essentially allow recursion to be replaced by iteration
50 Easier Meta-programming Variadic Templates Two components: Declaration template <typename T, typename... Args> void printf(const char *format, T value, Iteration Args... args); Uses either iteration over run-time arguments or iteration over compile-time size of Args parameter pack In latter case, uses sizeof...() operator on Args For more information, search for <tuple> implementation inside your compiler source.
51 Easier Meta-programming <type_traits> Library Provides various utilities to assist with metaprogramming Used primarily to ask questions about a type: Is type T integral? Is type T default constructible? Does type T have a particular operator defined?
52 Easier Meta-programming Summary decltype return type inference constexpr generalized compile-time expressions static_assert compile-time constraints variadic templates more efficient and usable template instantiation
53 Efficient Programming Introduction C++11 was designed with efficiency in mind A few features were added to the language to enable more efficient implementations of various familiar operations Perhaps the most significant feature added in this regard is the rvalue reference, that enables perfect forwarding This feature and more will be explained over the next few slides
54 Efficient Programming Overview std::move and rvalue references noexcept expression alignment support alignas alignof
55 Efficient Programming rvalue references An rvalue is any temporary that occurs on the right side of an assignment As compared to lvalues, which are storage locations on the left side of an assignment C++11 brings rvalue references, denoted by a type signature of T&& These are meant to be used in conjunction with the std::move function
56 Efficient Programming std::move Function std::move takes as an argument any one type and returns an rvalue reference of that type Does not trigger copy constructor This is very useful for: Implementing move constructors Implementing swap operations
57 Efficient Programming Move: What Does it Mean? A move operation is intended to be a destructive copy Instead of copying data over, move implemented correctly... Assigns the address of source pointers to destination pointers Copies over primitive values Sets source pointers to nullptr Either ignores source primitive values or sets them to 0 Since all pointers in the source are set to nullptr, they are not destructed This allows the execution of a technique known as perfect function forwarding
58 Efficient Programming Perfect Function Forwarding A move operation is intended to be a destructive copy Instead of copying data over, move implemented correctly... Assigns the address of source pointers to destination pointers Copies over primitive values Sets source pointers to nullptr Either ignores source primitive values or sets them to 0 Since all pointers in the source are set to nullptr, they are not destructed This allows the execution of a technique known as perfect function forwarding Very useful for factory functions, in particular For more details, refer to: C++ Rvalue References Explained
59 Efficient Programming noexcept Expression Declares to the compiler that a given function will NEVER propagate an exception A function declared as noexcept that encounters an exception will immediately terminate the program Allows the compiler to optimize those functions better Actual form is: function_type name(...) noexcept[(expression)] { }
60 Efficient Programming noexcept Expression By default, it occurs as noexcept(true), and is used as noexcept If the expression given in the parentheses can throw, then noexcept is disabled Allows for flexible conditional enabling of the noexcept feature Very important for generic programming!
61 Efficient Programming noexcept Suggestions The following are great functions to decorate with noexcept: Destructors these should never throw Move constructors Functions that were not designed to handle exceptions noexcept serves as both an indicator to the compiler and documentation for humans! For more details, refer to: noexcept.cpp
62 Efficient Programming Alignment Support Discussion of this feature will be limited as support for it is currently very limited Two new operators are added to C++: alignas alignof alignas allows for a memory region to be aligned on a specified boundary alignas(double) unsigned char c[1024]; alignas(16) float[100]; alignof returns the alignment of a give type const size_t n = alignof(float);
63 Efficient Programming Summary rvalue references Enable perfect forwarding, expressed as T&& std::move Function that performs a move operation noexcept expression Guarantees a function will not throw an exception alignment support alignas, alignof Particularly relevant for serialization and SIMD programming
64 Class Design Introduction Good class design is fundamental for making the most of C++ C++11 adds several features that target the realm of classes Some of these facilitate the implementation, some assist/enforce the interface Some particularly salient features include: Delegating constructors Constructor control Non-static member initialization These features and more are covered in the following slides
65 Controlling defaults: default and delete Class Design Overview New constructors: move and initializer list constructor, move assignment Delegating constructors Inheriting constructors Non-static member initialization Inheritance control: override, final Explicit conversion operators Inline name spaces for version support
66 Class Design Controlling Silent Defaults The compiler has always silently generated various class members if any one of them is defined Constructor: Default and copy Destructor Copy assignment Sometimes, you don't want to allow copying of a resource
67 Class Design Controlling Silent Defaults C++98/03 solution: Declare class NonCopyable with private copy assignment and copy constructor Have new class publicly inherit from NonCopyable C++11 solution: class X { X(const X&) = delete; const X& operator=(const X&) = delete; };
68 Class Design Controlling Silent Defaults C++11 also allows you to communicate whether a default member is used: class X { }; X() = default; ~X() = default; For more details, refer to: class_control.cpp
69 Class Design New Constructors C++11 gives you access to two new types of constructors: Initializer list constructor Move constructor Move assignment operator The first can be used to provide convenient use of your class The latter two are important to avoid unnecessary memory copying Implementation examples are given in: move.cpp
70 Class Design Delegating Constructors Many modern OO languages allow you to implement other constructors in terms of one constructor C++98/03 does not Beginning with C++11, this is now possible! For details, refer to: delegating_constructor.cpp Support requires GCC >= 4.7
71 Class Design Inheriting Constructors Allows members available in base class to be used in derived class Not currently supported by any compiler For details, refer to: inheriting_constructors.cpp
72 Class Design Non-static Member Initialization Previously, it was a compilation error to give default values to non-static class members C++11 makes this possible using the new initialization syntax Allows for simplified constructors For details, refer to: member_defaults.cpp Support requires GCC >= 4.7
73 C++11 introduces two new keywords for constraining designs through inheritance final Prevent virtual function from being overriden. override Class Design Inheritance Control Used to clearly express the intent that a given derived class function is meant to provide a new implementation for a base class function Helps the compiler flag errors where one accidentally overloads rather than overrides For more details, refer to: inheritance_control.cpp
74 Class Design Explicit Conversion Allows the use of the explicit keyword in conversion operators now Disables conversion in implicit context, if that is the desired result This feature has a limited range of use It primarily targets the case where you want to only allow conversion from one class to another during construction, but not in function call or copy contexts For details, refer to: explicit_conversion.cpp
75 Used primarily to provide version control within the language Rules: Class Design Inline Namespaces Can only be used within an enclosing namespace To reference elements of inline namespace, need only use name of enclosing namespace Inline namespace is invisible to external code For examples, refer to: inline_namespace.cpp
76 Class Design Summary Improvements to constructors Ability to control available constructors, new move and initializer list constructors, delegating constructors, inheriting constructors Additional improvements: Non-static member initialization, ability to control inheritance, explicit conversion operators, inline namespaces
77 New Libraries New containers: <unordered_*> - hash-implemented [multi]sets and [multi]maps <forward_list> singly-linked list <array> compile-time-sized array class <tuple> type container Concurrency support: threads, mutexes, locks, condition variables, promises, futures, atomics Random number generators <random> Regular expressions <regex> Compile-time rational arithmetic <ratio> Smart pointers <memory> Time management <chrono> For examples, refer to: libraries/*.cpp
78 Using C++11 Now C++11 depends on the availability of a fairly recent compiler Standard draft was published in early 2011, final draft in August GCC >= 4.6, LLVM Clang >= 3.0, MSVC >= 11.0 In many cases, the feature that you hope to use is available on only GCC and/or LLVM Clang For a few features, no compiler implements them If your goal is portability across compilers, DO NOT use C++11 C++`11 is not available on linprog
79 Using C++11 Now Compiler support Features lacking support
80 GCC C++11 Page Using C++11 Now Compiler Support Apache Compiler Support Matrix Clang LLVM C++11 Support Intel Compiler C++11 Support Visual Studio C++11 Compiler Support
81 Using C++11 Now Features Lacking Support The following is a list of features that no or almost no compiler supports: alignas (Clang 3.0) alignof (GCC 4.5, Clang 2.9) constexpr (GCC 4.6, Clang 3.1) Initializer Lists (GCC 4.4) Raw-string Literals (GCC 4.5, Clang All) Template alias (GCC 4.7, Clang 3.0, MSVC 12.1) Unrestricted unions (GCC 4.6, Clang 3.0) Range-for loop (GCC 4.6, Clang 3.0) Generalized attributes (MSVC 12.1 ) Non-static member initialization (GCC 4.7, Clang 3.0) In short, if you want the most salient C++11 features now, use GCC If portability is important, use Boost C++11 emulation layers
82 #include <iostream> #include <string> using namespace std; int main() { string msg = R ( Thanks! ) ; for (auto x : msg) cout << x; cout << endl; } return 0;
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 informationC++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 informationShort 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 informationCS201 - 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 informationC 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 informationCS
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 informationRAD Studio XE3 The Developer Force Multiplier
RAD Studio XE3 The Developer Force Multiplier Windows 8 Mac OS X Mountain Lion C++11 64-bit Metropolis UI C99 Boost Visual LiveBindings C++ Bjarne Stroustrup C with Objects (1979) Modeled OO after Simula
More informationBasic 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 informationSeptember 10,
September 10, 2013 1 Bjarne Stroustrup, AT&T Bell Labs, early 80s cfront original C++ to C translator Difficult to debug Potentially inefficient Many native compilers exist today C++ is mostly upward compatible
More informationAppendix. 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 informationC++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 informationFast 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 informationIBM Rational Rhapsody TestConductor Add On. Code Coverage Limitations
IBM Rational Rhapsody TestConductor Add On Code Coverage Limitations 1 Rhapsody IBM Rational Rhapsody TestConductor Add On Code Coverage Limitations Release 2.7.1 2 License Agreement No part of this publication
More informationCE221 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 informationAbsolute 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 informationIntroduction 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 informationIntroduction 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 informationOutline. 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 informationStructured 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 informationG52CPP C++ Programming Lecture 20
G52CPP C++ Programming Lecture 20 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Wrapping up Slicing Problem Smart pointers More C++ things Exams 2 The slicing problem 3 Objects are not
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationOutline. 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 informationIntroduction 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 informationC++ 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 informationIntroduction 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 informationExplicit Conversion Operator Draft Working Paper
Explicit Conversion Operator Draft Working Paper Lois Goldthwaite, Michael Wong IBM michaelw@ca.ibm.com ACCU Lois@LoisGoldthwaite.com Document number: N2223=07-0083 Date: 2007-03-11 Project: Programming
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationAxivion 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 informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationTokens, 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 informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationA brief introduction to C++
A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationProgramming with C++ as a Second Language
Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to
More informationObject Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
More informationIntroduction 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 informationI 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 informationMaking New Pseudo-Languages with C++
Making New Pseudo-Languages with C++ Build You a C++ For Great Good ++ A 10,000 Metre Talk by David Williams-King Agenda 1/4 Introduction 2/4 Polymorphism & Multimethods 3/4 Changing the Behaviour of C++
More informationCh. 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 informationstd::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 informationType Inference auto for Note: Note:
Type Inference C++11 provides mechanisms for type inference which make the compiler deduce the types of expressions. I m starting the book with type inference because it can make your code more concise
More informationIBM i Version 7.3. Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC
IBM i Version 7.3 Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC09-7852-04 IBM i Version 7.3 Programming IBM Rational Development Studio for i ILE C/C++ Language
More informationDr. Md. Humayun Kabir CSE Department, BUET
C++ Dr. Md. Humayun Kabir CSE Department, BUET History of C++ Invented by Bjarne Stroustrup at Bell Lab in 1979 Initially known as C with Classes Classes and Basic Inheritance The name was changed to C++
More informationObject-Oriented Programming for Scientific Computing
Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017
More informationCS3157: 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 informationRvalue 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 informationC++11/14 Rocks. VS2013 Edition. Alex Korban
C++11/14 Rocks VS2013 Edition Alex Korban 1 Contents Introduction 18 Type Inference 20 auto... 20 decltype... 24 Side e ects... 25 Trailing return types... 26 Non-standard behavior and bugs in Visual Studio
More informationAdvanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns
Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns This Advanced C++ Programming training course is a comprehensive course consists of three modules. A preliminary module reviews
More informationAdvanced 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 informationVariant: a type-safe union without undefined behavior (v2).
Variant: a type-safe union without undefined behavior (v2). P0087R0, ISO/IEC JTC1 SC22 WG21 Axel Naumann (axel@cern.ch), 2015-09-28 Contents Introduction 3 Version control 4 Discussion 4 Empty state and
More informationC++14 (Preview) Alisdair Meredith, Library Working Group Chair. Thursday, July 25, 13
C++14 (Preview) Alisdair Meredith, Library Working Group Chair 1 1 A Quick Tour of the Sausage Factory A Committee convened under ISO/IEC so multiple companies can co-operate and define the language Google
More informationProgramming in C and C++
Programming in C and C++ 5. C++: Overloading, Namespaces, and Classes Dr. Neel Krishnaswami University of Cambridge (based on notes from and with thanks to Anil Madhavapeddy, Alan Mycroft, Alastair Beresford
More informationObject-Oriented Programming
- oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne
More informationChapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.
hapter 1 INTRODUTION SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Objectives You will learn: Java features. Java and its associated components. Features of a Java application and applet. Java data types. Java
More informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
More informationCSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory
More informationCHAPTER 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 informationAbout Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals
More informationIBM i Version 7.2. Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC
IBM i Version 7.2 Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC09-7852-03 IBM i Version 7.2 Programming IBM Rational Development Studio for i ILE C/C++ Language
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationExpansion statements. Version history. Introduction. Basic usage
Expansion statements Version history Document: P1306R0 Revises: P0589R0 Date: 08 10 2018 Audience: EWG Authors: Andrew Sutton (asutton@uakron.edu) Sam Goodrick (sgoodrick@lock3software.com) Daveed Vandevoorde
More informationCSCI 1061U Programming Workshop 2. C++ Basics
CSCI 1061U Programming Workshop 2 C++ Basics 1 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output
More informationGEA 2017, Week 4. February 21, 2017
GEA 2017, Week 4 February 21, 2017 1. Problem 1 After debugging the program through GDB, we can see that an allocated memory buffer has been freed twice. At the time foo(...) gets called in the main function,
More informationRemedial 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 informationStream Computing using Brook+
Stream Computing using Brook+ School of Electrical Engineering and Computer Science University of Central Florida Slides courtesy of P. Bhaniramka Outline Overview of Brook+ Brook+ Software Architecture
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationAdding Alignment Support to the C++ Programming Language / Wording
Doc No: SC22/WG21/N2165 J16/07-0025 of project JTC1.22.32 Address: LM Ericsson Oy Ab Hirsalantie 11 Jorvas 02420 Date: 2007-01-14 to 2007.01.15 04:53:00 Phone: +358 40 507 8729 (mobile) Reply to: Attila
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example
More informationProblem Solving with C++
GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter
More information04-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 informationThe Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured
Introduction p. xxix The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured Language p. 6 C Is a Programmer's Language
More informationWelcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.
Welcome to Teach Yourself p. viii Acknowledgments p. xv Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p. 6 Standard C++: A Programming Language and a Library p. 8
More informationC++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017
C++\CLI Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 Comparison of Object Models Standard C++ Object Model All objects share a rich memory model: Static, stack, and heap Rich object life-time
More informationModern 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 informationIntroduce 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 informationC++ C and C++ C++ fundamental types. C++ enumeration. To quote Bjarne Stroustrup: 5. Overloading Namespaces Classes
C++ C and C++ 5. Overloading Namespaces Classes Alastair R. Beresford University of Cambridge Lent Term 2007 To quote Bjarne Stroustrup: C++ is a general-purpose programming language with a bias towards
More informationCS 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 informationGeneralized Constant Expressions
Doc. no. Date: September 21, 2003 Reply-To: Gabriel Dos Reis gdr@acm.org Abstract We suggest to generalize the notion of constant expressions to include calls to constant-valued functions. The purpose
More informationCh. 10: Name Control
Ch. 10: Name Control Static elements from C The static keyword was overloaded in C before people knew what the term overload meant, and C++ has added yet another meaning. The underlying concept with all
More informationNew wording for C++0x Lambdas
2009-03-19 Daveed Vandevoorde (daveed@edg.com) New wording for C++0x Lambdas Introduction During the meeting of March 2009 in Summit, a large number of issues relating to C++0x Lambdas were raised and
More informationCOMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking
Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationCCReflect has a few interesting features that are quite desirable for DigiPen game projects:
CCReflect v1.0 User Manual Contents Introduction... 2 Features... 2 Dependencies... 2 Compiler Dependencies... 2 Glossary... 2 Type Registration... 3 POD Registration... 3 Non-Pod Registration... 3 External
More informationC Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:
C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should
More informationQUIZ. 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 informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy
CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only
More information1/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 informationC++ Quick Guide. Advertisements
C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationHierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity
More informationChapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.
Chapter 1 GETTING STARTED SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Java platform. Applets and applications. Java programming language: facilities and foundation. Memory management
More informationCS93SI Handout 04 Spring 2006 Apr Review Answers
CS93SI Handout 04 Spring 2006 Apr 6 2006 Review Answers I promised answers to these questions, so here they are. I'll probably readdress the most important of these over and over again, so it's not terribly
More informationVariables. 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 informationRvalue 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 informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More informationProgramming in C++ 4. The lexical basis of C++
Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++
More informationDistributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes
Distributed Real-Time Control Systems Lecture 17 C++ Programming Intro to C++ Objects and Classes 1 Bibliography Classical References Covers C++ 11 2 What is C++? A computer language with object oriented
More information