From 3acde24ffbe065a43d33c6d153cd5bd566cf5da5 Mon Sep 17 00:00:00 2001 From: "Frank B. Brokken" Date: Wed, 9 Mar 2016 11:00:12 +0100 Subject: [PATCH] wip preparing for concepts --- annotations/yo/classtemplates.yo | 3 + annotations/yo/functiontemplates.yo | 2 +- annotations/yo/functiontemplates/intro.yo | 18 +- annotations/yo/functiontemplates/variables.yo | 7 +- annotations/yo/whatsnew.yo | 163 +----------------- 5 files changed, 26 insertions(+), 167 deletions(-) diff --git a/annotations/yo/classtemplates.yo b/annotations/yo/classtemplates.yo index 5225ba63..9541c183 100644 --- a/annotations/yo/classtemplates.yo +++ b/annotations/yo/classtemplates.yo @@ -75,6 +75,9 @@ includefile(classtemplates/variadic) lsubsect(NOTFN)(A bare bones `not_fn' negator) includefile(classtemplates/notfn) + subsect(Fold expressions) + includefile(classtemplates/fold) + lsect(TUPLES)(Tuples) includefile(classtemplates/tuples) diff --git a/annotations/yo/functiontemplates.yo b/annotations/yo/functiontemplates.yo index 6c4e4bb2..a93a021d 100644 --- a/annotations/yo/functiontemplates.yo +++ b/annotations/yo/functiontemplates.yo @@ -97,5 +97,5 @@ includefile(functiontemplates/sfinae) sect(Summary of the template declaration syntax) includefile(functiontemplates/summary) -sect(C++14: variable templates) +sect(variable templates) includefile(functiontemplates/variables.yo) diff --git a/annotations/yo/functiontemplates/intro.yo b/annotations/yo/functiontemplates/intro.yo index 95b8da1f..53e17e80 100644 --- a/annotations/yo/functiontemplates/intro.yo +++ b/annotations/yo/functiontemplates/intro.yo @@ -3,7 +3,7 @@ completely general (or abstract) functions or classes, based on generic types and/or (possibly inferred) constant values. In the chapters on abstract containers (chapter ref(CONTAINERS)) and the tt(STL) (chapter ref(STL)) we've already used these constructs, commonly known as the -emi(template mechanism). + emi(template mechanism). The template mechanism allows us to specify classes and algorithms, fairly independently of the actual types for which the templates are eventually going @@ -12,11 +12,17 @@ tailored to the particular data type(s) used with the template. This code is generated at i(compile-time) from the template's definition. The piece of generated code is called an emi(instantiation) of the template. -In this chapter the syntactic peculiarities of templates are covered. -The notions of em(template type parameter), em(template non-type parameter), -and emi(function template) are introduced and several examples of -templates are provided (both in this chapter and in chapter ref(CONCRETE)). -Template em(classes) are covered in chapter ref(TEMPCLASS). +In this chapter the syntactic peculiarities of templates are covered. The +notions of em(template type parameter), em(template non-type parameter), and +emi(function template) are introduced and several examples of templates are +provided (both in this chapter and in chapter ref(CONCRETE)). Template +em(classes) are covered in chapter ref(TEMPCLASS). For good reasons variadic +functions + hi(function: variadic)hi(variadic function) + are deprecated in bf(C++). However, em(variadic templates) tell us a +completely different story, and variadic templates are perfectly +acceptable. Both function- and class-templates can be defined as variadic +templates. Both forms are covered in section ref(VARIADIC). Templates already offered by the language include the abstract containers (cf. chapter ref(CONTAINERS)); the tt(string) (cf. chapter ref(String)); diff --git a/annotations/yo/functiontemplates/variables.yo b/annotations/yo/functiontemplates/variables.yo index 780afcef..a189ccec 100644 --- a/annotations/yo/functiontemplates/variables.yo +++ b/annotations/yo/functiontemplates/variables.yo @@ -1,8 +1,7 @@ In addition to function templates and class templates (cf. chapter -ref(TEMPCLASS)) the cXIV() standard allows the definition of variable -templates. Variable templates might come in handy when defining (function or -class) templates defining variables of types specified by template type -parameters. +ref(TEMPCLASS)) bf(C++) supports em(variable templates). Variable templates +might come in handy when defining (function or class) templates defining +variables of types specified by template type parameters. A variable template starts with a familiar tt(template) header, followed by the definition of the variable itself. The template header specifies a type, diff --git a/annotations/yo/whatsnew.yo b/annotations/yo/whatsnew.yo index fb758a3a..a2d5093e 100644 --- a/annotations/yo/whatsnew.yo +++ b/annotations/yo/whatsnew.yo @@ -1,6 +1,12 @@ This section is modified when the first or second part of the version number -changes (and occasionally also for the third field of the version number). +changes (and occasionally also for the third field of the version number). At +a major version upgrade the entries of the previous major version are kept, +and entries referring to older releases are removed. itemization( + it() Version 11.0.0 adds a chapter (ref(CONCEPTS)) about concepts, + re-introduced into bf(C++) since the C++17 (c++1z) standard. The C++17 + standard also adds em(fold expressions)to the language: covered in + a sub-section of section ref(VARIADIC). it() Version 10.5.0 contains a partial rewrite of facilities for specifying time. It includes functions tt(std::localtime, std::gmtime,) and tt(std::put_time) (section ref(TIME)), as well as @@ -34,159 +40,4 @@ changes (and occasionally also for the third field of the version number). formally supported since the C++11 standard. In addition some minor topics (e.g., tt(std::distance), some new syntax elements) were added to the annotations(). - it() In version 9.9.0 sections in chapter ref(STL) about specifying - absolute and relative time were rewritten and moved to sections of - their own. Sections about condition variablles were also rewritten. - it() Version 9.8.0 adds new sections in chapter ref(TEMPCLASS) about - static polymorphism, removes the concrete/a2x section, now made - superfluous by string conversion functions, and removes the C++11 - indicators from section headers. The C++ standard has by now been - implemented in Gnu's tt(g++) compiler (4.8.2). Note that the - tt(--std=c++11) compiler flag is still necessary if you want the - compiler to activate the C++11 extensions. - it() Version 9.7.0/9.7.1 adds several new sections (about time - specifications, system_error, error_category, error_code, this_thread, - locks) and other sections received a major overhaul (multi-threading, - lambda expressions, the main function). - it() Version 9.6.0 adds a section about tt(noexcept), deprecating -tt(throw) lists. Also the string chapter was updated. - it() Version 9.5.0 adapts the abstract containers to C++11, and adds a new -section (tt(Allocators)) just before introducing the sequential containers. -tt(make_shared), combining tt(shared_ptr) and (new). - it() Version 9.4.0 adds a new section to chapter ref(STL) about -tt(make_shared), combining tt(shared_ptr) and (new). - it() Version 9.3.0 refines the coverage of the tt(static_cast) and -tt(reinterpret_cast), following a suggestion provided by Gido Schoenmacker. - it() There are two major differences between versions 9.2.0 and -9.1.0. First, unrestricted unions are covered in more detail (cf. section -ref(UNIONS)). Second, by now url(flexc++)(http://flexcpp.org/) has been -released, and the sections previously using tt(flex) (cf. section -ref(BisonAndFlex)) are now using tt(flexc++). - it() Version 9.1.0 adds several new sections describing elements of -the language that by now have been implemented in Gnu's tt(g++) compiler -version 4.7. In the Annotations's contents these sections are clearly marked -as tt(C++11, 4.7). For section marked by merely C++11 it is assumed that -at least Gnu's compiler version 4.6 is available. Sections marked as tt(C++, -?) refer to elements in the C++11 (C++11) standard that haven't been -implemented yet in Gnu's tt(g++) compiler. Since C++11 is now the -`official' name of the new standard, references to C++0x have been replaced by -C++11. - - Installation limits of various integral types are frequently obtained -using tt(#define)s set in the tt() header file. However, the -tt(numeric_limits) template offers a (preferred) alternative, as -tt(numeric_limits) can also be used when defining templates. See chapter -ref(TEMPLATES) for details. - - To the distribution's ./contributions directory I added Jurjen Bokma's -(jurjen dot bokma at rug dot nl) 'makebook' recipe for creating a neatly bound -C++ Annotations book. The result is fabulous! Thanks, Jurjen! - - From now on, this `what's new' overview of changes to the Annotations is -restricted to the current and previous major release. Previous modifications -can be found in the distribution's tt(whatsnew.yo.old) file. - - Finally, typos were repaired. - - it() Version 9.0.0 was released following an extensive discussion with -several members of the C++ standards committee about the form of move special -members (move constructors, move assignment operators, other functions -defining rvalue type parameters). This discussion, in particular the -discussions I had with Dave Abrahams, Jonathan Wakely and Herb Sutter -resulted, eventually, in the annotations() relaxing the principle of -const-correctness, and in modifying the declarations and implementations of -move special members in this release. This shift in position (adopted by the -annotations() since its very early releases) profoundly affects much of the -annotations()'s contents, and warrants an upgrade to the next major release. - - The principle of const-correctness has always been visible in the -annotations(), defining return values of arithmetic binary operators like -tt(operator+) as tt(const) return values. Here the annotations() also applied -another principle: `do as the ints do'. When (e.g.,) adding two tt(int)-values -the result is customarily considered immutable. I.e., tt((a + 5) += 4) makes -no sense, with the compiler refusing to compile the statement. But is tt(a + -5) a constant? There is no simple answer to that question. Before the advent -of C++11 I thought the answer was `yes', but strangely enough, the answer was -not always `yes'. If the above tt(a) is of type tt(std::string) then tt((a + -"b") += "c") suddenly em(is) accepted by the compiler. The annotations() never -adopted this scheme, but stuck to the rule `do as the ints do' by defining the -return types of functions returning values as tt(const) values. - - C++11 added rvalue references to the language, and then I eventually was -convinced that defining tt(const) return values should in general be -avoided. As C++11 allows temporaries to be associated with rvalue references, -a completely new situation is created. Suddenly intermediate -tt(int) values em(can) be modified, as illustrated by the following snippet of -code: - verb( - void fun(int &&tmp) - { - tmp += 4; // compiles OK - } - int main() - { - int a = 8; - fun(a + 5); - } - ) - The snippet of code also shows the standard definition of an rvalue -reference as an entity of type `tt(Type &&)'. This definition of rvalue -reference parameters is now used all over the annotations(), together with -using non-const return types of functions returning values. - - Many readers have submitted suggestions for improvements since version -8.3.1 was released. A big `thank you' to all of you, but in particular to -bf(Francesco Poli) who continued to send in suggestions for improvements for a -period of almost two years. His suggestions were an invaluable source of -improvement for almost every single section of the annotations(). Thanks, -Francesco, for all the effort you've put in improving this document! - - Finally, in version 9.0.0 sections were added and sometimes moved. The -section about em(unrestricted unions) was completed and moved to the -`Containers' chapter, and a new section about adding binary operators to -classes using function templates was added to the annotations()' final chapter -(concrete examples). - it() Version 8.3.1: usually a subminor version isn't explicitly -mentioned in this section, but in this case the changes from 8.3.0 to 8.3.1 -were the result of many, many small and not so small corrections submitted by -Francesco Poli who did a very thorough close reading job on the -Annotations. Thanks again, Francesco, for all your contributions! - it() Version 8.3.0 adds sections about various (member) function adaptors -and adds/rephrases several sections about statistical distribution functions -(chapter ref(STL)). When covering elements from the C++-0x standard it is -assumed that the Gnu tt(g++) compiler version 4.4 is available. With elements -of the C++-0x standard requiring versions beyond 4.4 the required versions -are explicitly mentioned, if already known. All suggestions sent in by various -readers have also been processed, their help to improve the quality of the -annotations() is greatly appreciated: thanks! - it() Version 8.2.0 adds a section about casting tt(shared_ptrs) (section -ref(SHAREDCAST)) and about sharing arrays of objects (ref(SHAREDARRAY)). - it() Version 8.1.0 was released following a complete overhaul of the -annotations(), with two pre-leases in between. Many inconsistencies that had -crept into the text and examples were removed, streamlining the text and -synchronizing examples with the text. All of the code examples have received -a work-over, replacing tt(endl) by tt('\n'), making virtual functions private, -etc., etc. The sections labeled C++11 were improved and sections showing -C++11 now also mention the tt(g++) version in which the new feature will -be made available, using tt(?) if this is as yet unknown. No version is shown -if the feature is already available in tt(g++) 4.3 (or in one of its -subreleases, like 4.3.3). I received a host of suggestions from Francesco -Poli (thanks, Francesco (and several others), for all the effort you've put -into sending me those corrections). - it() Version 8.0.0 was released as a result of the upcoming new bf(C++) -standard+footnote(ti(http://en.wikipedia.org/wiki/C++11)) becoming (partially) -available in the Gnu tt(g++) - compiler+footnote(http://gcc.gnu.org/projects/cxx0x.html). - Not all new elements of the new standard (informally called the C++0x -standard) are available right now, and new subreleases of the bf(C++) -Annotations will appear once more elements become implemented in the tt(g++) -compiler. In section ref(COMPILATION) the way to activate the new standard is -shown, and new sections covering elements of the new standard show C++11 -in their section-titles. - - Furthermore, two new chapters were added: the STL chapter is now split -in two. The STL chapter now covers the STL except for the em(Generic -Algorithms) which are now discussed in a separate chapter. Name spaces, -originally covered by the introductory chapter are now also covered in a -separate chapter. )