On the Coroutines TS
|
|
- Howard Hubbard
- 5 years ago
- Views:
Transcription
1 Document number: P1329R0 Date: Reply To: Mihail Mihaylov ( mmihailov@vmware.com ) Vassil Vassilev ( v.g.vassilev@gmail.com ) Audience: WG21 Evolution Working Group On the Coroutines TS We have familiarized ourselves with the Coroutines TS [1], and two other proposals - Core Coroutines [2] and Resumable Expressions [3]. We have also spent time experimenting with the Coroutine TS in a preexisting production code base. Based on this, our position is that the Coroutines TS should not be merged into the working draft. We have concerns about the design of the feature and in our opinion the high demand for the feature should not be a reason to adopt the design, if a better one is possible. Instead of adopting the Coroutines TS we would prefer improving the Core Coroutines proposal or exploring other alternatives. Our concerns about the Coroutines TS fall into three categories interface, terminology and performance. Interface Our most general concern is that coroutines as proposed in the Coroutines TS are not first class citizens of the C++ language. In the TS, a coroutine definition essentially defines a factory function which returns a type-erased handle for it. The actual coroutine has no type, and no scope. As such, coroutines cannot be used in many ways in which first class types can. They cannot be allocated with automatic lifetime, including being aggregated into other objects, they cannot be used for dispatch and in general are not as naturally composable with other elements of the language as first-class features. We would favour a design which makes coroutines first class citizens of the language. A specific concern is that the lifetime of the coroutine frame and the lifetime of the wrapper object that is created when the coroutine is instantiated are separate. As the promise object is allocated on the coroutine frame, this makes it harder for programmers to reason about the lifetime of values and exceptions returned by the coroutine. We would favour a design where the coroutine frame is a part of the wrapper object (the coroutine lambda in the case of the Core Coroutines proposal), which would allow programmers 1
2 to reason about the coroutine lifetime through the lifetime of the wrapper and offer experts better control of the coroutine frames. Another issue is the policy-based customization. While this approach is very useful in many cases, in the context of the Coroutines TS over time it has evolved into a big number of customization points. We believe that it is possible to achieve the same level of customization by just overriding a small number of operations. Furthermore, the customization points in the Coroutines TS allow counterintuitive behavior. For example, it s possible to define a promise where the co_yield expression will not yield. We would favour a design which has a smaller and simpler customization interface. Terminology We echo the concern already expressed by others about the choice of the co_await keyword. The coroutine concept was introduced 60 years ago, and has well-established terminology. Co_await does not follow this terminology and focuses on a specific use case instead of on the essence of coroutines. We share the concern regarding the risk of collisions between new keywords and existing identifiers used in user code. Still, the Coroutines TS proposal suggests adding three of them with the co_ prefix. So we presume there is a general acceptance of new keywords starting with an uncommon prefix. In addition, other TSes seem to have reached consensus on stealing very popular identifiers. We would favour a design which employs either the function call syntax or keywords that include in their spelling the verbs yield, resume and suspend, the way co_yield does. Performance We are concerned about the heap allocation of the coroutine frame. Our understanding is that the motivation for this design choice was to make it possible for suspended coroutines to leave the scope where they were created including teleporting them to other threads. To address this concern, the Coroutines TS relies heavily on the heap elision optimization. We are concerned that there will be many use cases where the compiler won t be able to determine correctly the lifetime of the coroutine frame, and will be forced to go with the more conservative estimate and keep the heap allocation. 2
3 In the context of coroutines we can expect that it will be hard for compilers to detect the optimization opportunity in cases when coroutines are aggregated into objects, nested within other coroutines, returned from factory functions, etc. The fact that the coroutine frame could easily outlive its wrapper object can further complicate the task of the compiler. Following are some examples of cases when heap elision doesn t work (with the latest version of clang in Compiler Explorer at O2) [4]. First, let s define a simple coroutine wrapper class and two simple coroutines that use it: #include <memory> #include <experimental/coroutine> using namespace std ; template < typename V> class RawCoroutine { public : struct promise_type ; using handle = std ::experimental::coroutine_handle<promise_type>; struct promise_type { V value; exception_ptr e; auto get_return_object () { return RawCoroutine{handle::from_promise(* this ); auto initial_suspend () { return std ::experimental::suspend_always(); auto final_suspend () { return std ::experimental::suspend_always(); auto return_value (V v) { value = v; return std ::experimental::suspend_never(); void unhandled_exception () { e = current_exception(); 3
4 ; auto yield_value (V v) { value = v; return std ::experimental::suspend_always(); RawCoroutine( const RawCoroutine&) = delete ; RawCoroutine(RawCoroutine&& other) : _coro(other._coro) { other._coro = nullptr ; RawCoroutine(handle h) : _coro(h) { ~RawCoroutine() { _coro.destroy(); V operator ()() { _coro(); if (_coro.promise().e) rethrow_exception(_coro.promise().e); else return _coro.promise().value; bool done () { return _coro.done(); ; private : handle _coro; ; static RawCoroutine< int > SimpleRange() { for ( i < 10; ++i) co_yield i; co_return 10; static RawCoroutine< int > CompositeRange() { RawCoroutine< int > coro = SimpleRange(); co_yield coro () * 2; 4
5 co_return -1; struct Base { virtual ~Base() { virtual RawCoroutine< int > coro() = 0; ; struct Derived : Base { RawCoroutine< int > coro() override { for ( i < 10; ++i) co_yield i; ; co_return 10; Next, let s look at several examples where we use these coroutines and whether clang will detect that it can use heap elision. For a simple scoped coroutine, clang applies heap elision: RawCoroutine< int > coro = SimpleRange(); i += coro(); But it doesn t apply it if the coroutine wrapper itself is on the heap: auto coro = make_unique<rawcoroutine< int >>(SimpleRange()); while (!coro->done()) i += (*coro)(); 5
6 Similarly, when the coroutine wrapper is itself wrapped in another object, clang elides the coroutine handle allocation when wrapper object is on the stack: struct Wrapper { Wrapper() : coro(simplerange()) { ; RawCoroutine< int > coro; Wrapper wrapper; while (!wrapper.coro.done()) i += wrapper.coro(); But not when it s on the heap: struct Wrapper { Wrapper() : coro(simplerange()) { ; RawCoroutine< int > coro; auto wrapper = make_unique<wrapper>(); while (!wrapper->coro.done()) i += wrapper->coro(); In the case of a nested coroutine, clang elides the heap allocation of the frame of the outer coroutine, but not of nested one: RawCoroutine< int > coro = CompositeRange(); i += coro(); 6
7 The compiler also fails to elide the allocation when the coroutine is virtual: unique_ptr <Base> b = make_unique<derived>(); RawCoroutine< int > coro = b->coro(); i += coro(); The compiler elides the allocation when the coroutine is created by a factory function: struct Factory { static RawCoroutine< int > Create() { return SimpleRange(); ; RawCoroutine< int > coro = Factory::Create(); i += coro(); But not when the factory function is in another translation unit (or not inlined for some other reason): struct Factory { // No inline, to simulate another translation unit static RawCoroutine< int > Create() attribute ((noinline)) { return SimpleRange(); ; 7
8 RawCoroutine< int > coro = Factory::Create(); i += coro(); These are just some examples, but we can expect many more scenarios where the coroutine frame is allocated on the heap, even though the coroutine doesn t leave the scope where it s created. More importantly, even if the heap elision optimization becomes completely reliable in the future, it will be hard for developers to predict when it will take place. This will make it hard for programmers to reason about the performance of their code. For these reasons, we favour a design which makes it explicit how the coroutine frame is allocated. Path forward The Bulgarian NB is exploring alternative directions and we plan to present a preview of a proposal at the next meeting in Kona. Still, we feel that by opposing the Coroutines TS, we have the obligation to present at least a direction for improvement, so we are sharing a very preliminary view of what we are working on. We would favour a design: which makes coroutines first class citizens of the language; where the coroutine frame is a part of the wrapper object (the coroutine lambda in the case of the Core Coroutines proposal), which would allow programmers to reason about the coroutine lifetime through the lifetime of the wrapper and offer experts better control of the coroutine frames; which has a smaller and simpler customization interface; which employs either the function call syntax or keywords that include in their spelling the verbs yield, resume and suspend, the way co_yield does; which makes it explicit how the coroutine frame is allocated. The core idea in our future proposal is for coroutine definitions to define classes instead of factory functions. The pseudo code: std ::coroutine< int > Range( int start, int end) { for ( int i = start; i < end - 1; ++i) yield(i); 8
9 return end; Would declare a class Range that derives from std ::coroutine< int > which has in its memory layout reserved space for the captures and the coroutine frame and suspension point: class Range : public std ::coroutine< int > { coroutine_state<range> frame; // Not visible in // the coroutine body int start; // Visible in the coroutine body int end; // Visible in the coroutine body public : Range( int start, int end) : coroutine< int >(...), start(start), end(end) { int operator ()() { // Transformed function body //... The yield(i) statement would be a method of the base class std ::coroutine< int >, so it would be only available in the context of a coroutine and would have a low risk of clashing with user identifiers. If that is not acceptable, we would opt for keywords like co_yield, co_suspend and co_return. Once defined, the coroutine can be used as any functor object that the programmer could write by hand: // Automatic storage duration. Range rangescoped (0, 10); while (!rangescoped.done()) i += rangescoped(); // Dynamic storage duration. auto rangedyn = make_unique<range>(0, 10); while (!ran10gedyn->done()) i += (*rangedyn)(); 9
10 // Passing by reference Range r (10, 20); i += foo(r); // Aggregation in other classes struct Wrapper { Wrapper( int end) : range(0, end) { ; Range range; The proposed lowering also allows programmers to create their own coroutine types by deriving from the base std ::coroutine type. This change or a similar one can be applied directly to the Coroutines TS design as well as to the Core Coroutines proposal. But if accepted, such a change to any of these proposals will necessarily delay its merging at least until the meeting in Kona. So we would like to take this time to develop our proposal further, as we are interested in exploring other sides of the coroutines design too. We intend to work closely with Gor Nishanov and the authors of the Core Coroutines proposal and we will strongly consider changes to the existing proposals instead of a completely new one, if possible. Acknowledgements The authors would like to thank Anton Stoyanov, Aleksandar Cheshmedjiev, Georgi L Dimitrov, Hristosko Chaushev, Petko Padevski, Peter Dimov, Stanimir Lukanov and Viktor Kaltchev for comments on early drafts of this proposal. Thanks again to all those involved in the Coroutines TS, and particularly Gor Nishanov, for exploring the coroutines design space and providing a basis for this feedback paper. References [1] Coroutines TS, N4760, [2] Core Coroutines, P1063R1, [3] Resumable expressions, P0114R0, [4] 10
This paper explains in more detail some of the proposed simplifications from P1342R0.
Paper. Audience Author P1477R0 Evolution Lewis Baker Date 2019-01-20 Coroutines TS Simplifications Abstract The paper P0973R0 raised a concern about the perceived size and complexity of
More informationCoroutine concepts and metafunctions
Document No. P1288R0 Date 2018-10-07 Reply To Audience Lewis Baker SG1, LEWG Coroutine concepts and metafunctions Abstract The Coroutines TS introduces the ability to co_await a value from
More informationCoroutines TS Use Cases and Design Issues
Document number: P0973R0 Date: 2018-03-23 Reply To: Geoff Romer ( gromer@google.com ), James Dennett ( jdennett@google.com ) Audience: WG21 Evolution Working Group Coroutines TS Use Cases and Design Issues
More informationawait/yield: C++ coroutines Zbigniew Skowron 30 November 2016
await/yield: C++ coroutines Zbigniew Skowron 30 November 2016 Agenda Current status Overview and motivation Stackful vs. stackless Coroutines as generators Coroutines instead of callbacks Awaitable types
More informationCore Coroutines. Making coroutines simpler, faster, and more general
Document number: P1063R1 Date: 2018-10-05 Reply To: Geoff Romer ( gromer@google.com ) James Dennett ( jdennett@google.com ) Chandler Carruth ( chandlerc@google.com ) Audience: WG21 Evolution Working Group
More informationWorking Draft, C++ Extensions for Coroutines
Document Number: Date: 2018-02-11 Revises: N4723 Reply to: Gor Nishanov Working Draft, C++ Extensions for Coroutines Note: this is an early draft. It s known to be incomplet and incorrekt,
More informationWorking Draft, C++ Extensions for Coroutines
Document Number: Date: 2018-06-24 Revises: N4736 Reply to: Gor Nishanov Working Draft, C++ Extensions for Coroutines Note: this is an early draft. It s known to be incomplet and incorrekt,
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 informationDraft wording for Resumable Functions
Document Number: Date: 2015-04-10 Revises: None Reply to: Gor Nishanov Microsoft gorn@microsoft.com Draft wording for Resumable Functions Note: this is an early draft. It s known to be incomplet and incorrekt,
More informationImproving the Return Value of Erase-Like Algorithms
Improving the Return Value of Erase-Like Algorithms Document #: P0646R0 Date: 2017-05-19 Project: Programming Language C++ Library Evolution Working Group Reply-to: Marc Mutz 1 Introduction
More informationMODERN AND LUCID C++ ADVANCED
Informatik MODERN AND LUCID C++ ADVANCED for Professional Programmers Prof. Peter Sommerlad Thomas Corbat Director of IFS Research Assistant Rapperswil, FS 2016 LIBRARY API/ABI DESIGN PIMPL IDIOM HOURGLASS
More informationregister 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 informationWorking Draft, Technical Specification for C++ Extensions for Coroutines
Document Number: Date: 2016-11-27 Revises: P0057R7 Reply to: Gor Nishanov Working Draft, Technical Specification for C++ Extensions for Coroutines Note: this is an early draft. It
More informationSynchronously waiting on asynchronous operations
Document No. P1171R0 Date 2018-10-07 Reply To Audience Lewis Baker SG1, LEWG Synchronously waiting on asynchronous operations Overview The paper P1056R0 introduces a new std::experimental::task
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 informationImplicit Evaluation of auto Variables and Arguments
Implicit Evaluation of auto Variables and Arguments Document number: N4035 (update of N3748) Authors: Joël Falcou University Paris XI, LRI Peter Gottschling SimuNova Herb Sutter Microsoft Date: 2013-08-30
More informationBotet C++ generic match function P0050
Document number: P0050 Date: 2015 09-24 Project: ISO/IEC JTC1 SC22 WG21 Programming Language C++, Library Evolution Working Group Reply-to: Vicente J. Botet Escriba C++ generic
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 informationWording for Coroutines
Document Number: Date: 2016-02-12 Revises: P0057R1 Audience: CWG / LEWG Authors: Gor Nishanov Jens Maurer Richard Smith Daveed Vandevoorde
More informationstd::assume_aligned Abstract
std::assume_aligned Timur Doumler (papers@timur.audio) Chandler Carruth (chandlerc@google.com) Document #: P1007R0 Date: 2018-05-04 Project: Programming Language C++ Audience: Library Evolution Working
More informationasynchronous programming with allocation aware futures /Naios/continuable Denis Blank Meeting C
Continuable asynchronous programming with allocation aware futures /Naios/continuable Denis Blank Meeting C++ 2018 Introduction About me Denis Blank Master s student @Technical
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 informationAbstract This paper proposes the ability to declare multiple variables initialized from a tuple or struct, along the lines of:
Structured bindings Document Number: P0144R1 Date: 2016-02-03 Reply-to: Herb Sutter (hsutter@microsoft.com), Bjarne Stroustrup (bjarne@stroustrup.com), Gabriel Dos Reis (gdr@microsoft.com) Audience: EWG
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 informationIntegrating Concepts: Open items for consideration
Integrating Concepts: Open items for consideration John H. Spicer, Hubert S.K. Tong, Daveed Vandevoorde Project: ISO/IEC JTC 1/SC 22/WG 21/C++ Document #: Date: 2017-06-17 Revises: None Working Group:
More informationC++ Module TS Issues List Gabriel Dos Reis Microsoft
P0501R3 2018-01-30 Reply-To: gdr@microsoft.com Active Issues C++ Module TS Issues List Gabriel Dos Reis Microsoft [5] Static local variables [John Spicer, 11/8/2016] Should there be a restriction on local
More information10. Functions (Part 2)
10.1 Overloaded functions 10. Functions (Part 2) In C++, two different functions can have the same name if their parameters are different; either because they have a different number of parameters, or
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 informationAllowing Class Template Specializations in Associated Namespaces (revision 1)
Allowing Class Template Specializations in Associated Namespaces (revision 1) Document number: P0665R1 Reply-to: Tristan Brindle tcbrindle@gmail.com Date: 2018-05-06 Audience: Evolution Working Group Summary
More informationC++ Objects Overloading Other C++ Peter Kristensen
Peter Kristensen 2012-12-03 Peter Kristensen Outline 1 What s this thing anyway 2 3 Functions Operators 4 Templates STL A better C 11 Peter Kristensen Overview What s this thing anyway 1 What s this thing
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 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 informationExtended friend Declarations
Document number: Date: 19 September, 2003 Reply to: William M. Miller The MathWorks, Inc. wmm@world.std.com Extended friend Declarations I. The Problem According to the current Standard, 11.4 2, An elaborated-type-specifier
More informationModules:Context-Sensitive Keyword
Document Number: P0924r1 Date: 2018-11-21 To: SC22/WG21 EWG Reply to: Nathan Sidwell nathan@acm.org / nathans@fb.com Re: Merging Modules, p1103r2 Modules:Context-Sensitive Keyword Nathan Sidwell The new
More informationModules:Dependent ADL
Document Number: P0923r1 Date: 2018-05-04 To: SC22/WG21 EWG Reply to: Nathan Sidwell nathan@acm.org / nathans@fb.com Re: Working Draft, Extensions to C ++ for Modules, n4720 Modules:Dependent ADL Nathan
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 informationUNIFYING ASYNCHRONOUS APIS IN C++ STANDARD LIBRARY
Paper no. P1341R0 Date 2018-11-25 Reply To Lewis Baker Audience SG1, LEWG UNIFYING ASYNCHRONOUS APIS IN C++ STANDARD LIBRARY Unifying executors, sender/receiver, coroutines, parallel algorithms
More informationImplicit 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 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 informationLesson 13 - Vectors Dynamic Data Storage
Lesson 13 - Vectors Dynamic Data Storage Summary In this lesson we introduce the Standard Template Library by demonstrating the use of Vectors to provide dynamic storage of data elements. New Concepts
More informationAmerican National Standards Institute Reply to: Josee Lajoie
Accredited Standards Committee X3 Information Processing Systems Operating under the procedures of American National Standards Institute Doc No: X3J16/95-0051 WG21/N0651 Date: March 3, 1995 Page 1 of 15
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 informationSymbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is
More information1: Introduction to Object (1)
1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface
More informationBotet C++ generic overload functions P0051
Document number: P0051 Date: 2015-09-22 Project: ISO/IEC JTC1 SC22 WG21 Programming Language C++, Library Evolution Working Group Reply-to: Vicente J. Botet Escriba C++ generic
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 informationClasses. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).
UNITII Classes Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT). It s a User Defined Data-type. The Data declared in a Class are called Data- Members
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 informationClass Types in Non-Type Template Parameters
Class Types in Non-Type Template Parameters Document #: D0732R0 Date: 2017-11-11 Project: Programming Language C++ Audience: Evolution Reply-to: Jeff Snyder 1 TL;DR We should
More informationSEMANTIC ANALYSIS TYPES AND DECLARATIONS
SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
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 informationLesson 12 - Operator Overloading Customising Operators
Lesson 12 - Operator Overloading Customising Operators Summary In this lesson we explore the subject of Operator Overloading. New Concepts Operators, overloading, assignment, friend functions. Operator
More informationAn Introduction to C++
An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface
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 informationWhat about Object-Oriented Languages?
What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an ALL? (ALGOL-Like Language) Data-centric name scopes for values
More informationTutorial 7. Y. Bernat. Object Oriented Programming 2, Spring Y. Bernat Tutorial 7
Tutorial 7 Y. Bernat Object Oriented Programming 2, Spring 2016 Exercise 4 STL Outline Part I Today's Topics 1 Exercise 4 2 STL Containers - continue Lambda functions Algorithms Exercise 4 STL Exercise
More informationMaking operator?: overloadable
Document Number: Date: 2018-02-12 Reply-to: Matthias Kretz Audience: EWG Making operator?: overloadable This paper explores user-defined overloads of operator?:. ABSTRACT CONTENTS 1 Introduction
More informationStatic If Considered
Document number: N3613 Date: 2013-03-16 Study group: Concepts Reply to: Bjarne Stroustrup Gabriel Dos Reis Andrew Sutton Static If Considered Bjarne
More informationAbstract This paper proposes the ability to declare multiple variables initialized from a tuple or struct, along the lines of:
Structured bindings Document Number: P0144R0 Date: 2015-10-14 Reply-to: Herb Sutter (hsutter@microsoft.com), Bjarne Stroustrup (bjarne@stroustrup.com), Gabriel Dos Reis (gdr@microsoft.com) Attention: EWG
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 informationSupporting async use-cases for interrupt_token
Document No. P1287R0 Date 2018-10-08 Reply To Audience Lewis Baker < lbaker@fb.com > Kirk Shoop < kirkshoop@fb.com > SG1, LEWG Supporting async use-cases for interrupt_token Abstract The jthread paper
More informationMore Improvements to std::future<t> - Revision 1
Document number: N4048 Date: 2014-05-26 Revises: N3865 Project: JTC1.22.32 Programming Language C++ Reply to: Vicente J. Botet Escribá More Improvements to std::future - Revision
More informationResumable Expressions
Document Number: N4453 Date: 2015-04-12 Reply To Christopher Kohlhoff 1 Introduction Resumable Expressions This paper proposes resumable expressions, a pure language extension for
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 informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationModern and Lucid C++ Advanced for Professional Programmers. Part 12 Advanced Library Design. Department I - C Plus Plus Advanced
Department I - C Plus Plus Advanced Modern and Lucid C++ Advanced for Professional Programmers Part 12 Advanced Library Design Thomas Corbat / Prof. Peter Sommerlad Rapperswil, 23.02.2017 HS2017 Topics
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 informationAn introduction to C++ template programming
An introduction to C++ template programming Hayo Thielecke University of Birmingham http://www.cs.bham.ac.uk/~hxt March 2015 Templates and parametric polymorphism Template parameters Member functions of
More informationLet 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 informationWording for lambdas in unevaluated contexts
Wording for lambdas in unevaluated contexts Document #: P0315R4 Date: 2017-11-10 Project: Programming Language C++ Audience: Core Working Group Reply-to: Louis Dionne Hubert Tong
More informationModules: Contexts of Template Instantiations and Name Lookup Gabriel Dos Reis Microsoft
Modules: Contexts of Template Instantiations and Name Lookup Gabriel Dos Reis Microsoft Background One of the design principles behind modules is to ensure that the working programmer does not need to
More informationP0444: Unifying suspend-by-call and suspend-by-return
P0444: Unifying suspend-by-call and suspend-by-return Document number: P0444R0 Date: 2016-10-14 Reply-to: Nat Goodspeed Audience: SG1, EWG Abstract This paper is a response to P0073R2
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 informationTransformation Trait remove_cvref 1
Transformation Trait remove_cvref 1 Document #: WG21 P0550R2 Date: 2017-07-17 Project: JTC1.22.32 Programming Language C++ Audience: LWG Reply to: Walter E. Brown Contents 1 Introduction.............
More informationResumable Functions. 1. The Problem
Doc No: N3650 Supersedes: N3564 Date: 2013-05-02 Reply to: Niklas Gustafsson < niklas.gustafsson@microsoft.com> Deon Brewis < deonb@microsoft.com> Herb Sutter Sana Mithani
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 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 informationWorking Draft, Extensions to C++ for Modules
Document Number: Date: 2017-03-19 Revises: N4637 Reply to: Gabriel Dos Reis Microsoft gdr@microsoft.com Working Draft, Extensions to C++ for Modules Note: this is an early draft. It s known to be incomplet
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 informationNAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)
NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14) Some Material for your reference: Consider following C++ program. // A program
More informationC++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 informationCSE 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 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 informationDeclaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:
Declarations Based on slides from K. N. King Declaration Syntax General form of a declaration: declaration-specifiers declarators ; Declaration specifiers describe the properties of the variables or functions
More informationJava: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.
Java: Classes Introduction A class defines the abstract characteristics of a thing (object), including its attributes and what it can do. Every Java program is composed of at least one class. From a programming
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
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 informationOn launder() Which Problem shall launder() solve? N. Josuttis: P0532R0: On launder()
Project: ISO JTC1/SC22/WG21: Programming Language C++ Doc No: WG21 P0532R0 Date: 2017-01-14 Reply to: Nicolai Josuttis (nico@josuttis.de) Audience: CWG, EWG, LEWG, LWG Prev. Version: ---- On launder()
More informationA 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 informationProposed Wording for Concurrent Data Structures: Hazard Pointer and Read Copy Update (RCU)
Document number: D0566R1 Date: 20170619 (pre Toronto) Project: Programming Language C++, WG21, SG1,SG14, LEWG, LWG Authors: Michael Wong, Maged M. Michael, Paul McKenney, Geoffrey Romer, Andrew Hunter
More informationTime(int h, int m, int s) { hrs = h; mins = m; secs = s; } void set(int h, int m, int s) { hrs = h; mins = m; secs = s; }
Inheritance The following class implements time in hh:mm::ss format: class { public: () { = 0; = 0; = 0; (int h, int m, int s) { = h; = m; = s; void set(int h, int m, int s) { = h; = m; = s; void tick()
More informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationCOSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26
COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.
More informationcommon_type and duration
common_type and duration Document #: WG21 P0548R1 Date: 2017-03-03 Project: JTC1.22.32 Programming Language C++ Audience: LWG Reply to: Walter E. Brown Contents 1 Introduction.............
More informationContents A Little C++
Contents 1 A Little C++ 3 1.1 Classes, Methods and Constructors...................................... 3 1.2 Inheritance and Data Encapsulation..................................... 4 1.2.1 Method Overriding...........................................
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 informationObject oriented programming. Encapsulation. Polymorphism. Inheritance OOP
OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes
More informationmemory_resource_ptr: A Limited Smart Pointer for memory_resource Correctness
Document #: Date: 2015-10-14 Authors: Pablo Halpern, phalpern@halpernwightsoftware.com Dietmar Kühl, dkuhl@bloomberg.net memory_resource_ptr: A Limited Smart Pointer for memory_resource Correctness 1 Abstract
More information