The C++ Story pulls together presentations on C++ syntax and semantics, and example code,
to present a tutorial on the C++ programming language. Also
provided are exercises at the end of most chapters.
The story consists of 12 chapters on: basics of C++ syntax and semantics, classes, class relationships
and their use to build compound objects, templates, template specialization, and template metaprogramming.
The concluding chapters cover standard libraries and other interesting topics.
Chapter 1 focuses on C++ language syntax and semantics before classes. It discusses all the
things C++ added to C, describes its type system, points to basic code examples to review,
and ends with a discussion of C++ models for compilation, program execution, and use of memory.
Finally, there are a set of exercises for you to test your skills. The exercises start out
with simple requests with discussion about how you satisfy them. Later exercises require some
design on your part.
This page provides brief descriptions of the major C++ language features and a few of its
many libraries.
It also describes a few libraries that I built for CSE687 - Object Oriented
Design class work.
C++ types, type qualifiers and type structures are presented first. That's followed by
type system casts, new standard types (C++17), data initialization, and smart pointers.
The last part covers building data structures with the STL library components.
Chapter 4 focuses on manipulating data. First it covers type coercions, copy construction,
copy assignment, functions, function pointers, methods, method pointers, functors, and lambdas.
Next comes callable objects, passing function and method parameters and side effects,
return values and return value optimization. The chapter concludes with STL algorithms and
testing.
Topics are basic classes, class methods with examples, building value types, and resource allocation.
Next is class anatomy, a survey of a lot of moving parts, followed by compiler-generated methods.
The chapter ends with examples of classes from the C++ Repositories.
The chapter starts with an overview of the four fundamental relationships: inheritance, composition,
aggregation, and using. That is followed by object layout, and an important compound object layout
demonstration. The chapter closes with inheritance, run-time polymorphism, and virtual dispatching,
followed by two non-trivial examples.
Template functions, and overloading start the chapter. Then type categories, type transformations,
and substitution failure is not an error (SFINAE). The first part ends with examples.
The second part focuses on template classes, class template parameters, and template class specialization.
Chapter 7 ends with two practical examples.
C++ template semantics require compiler computations as part of the build process. There is a functional
language that directs these compile-time computations to build things like variadic functions and classes.
This chapter begins with a simple example using that functional language. It continues with variadic functions,
variadic classes, and both standard and custom compile-time entities and type traits. The chapter closes
with compile-time selections and two examples.
Chapter 9 provides a quick summary of both standard and custom libraries via a table of links.
Stream Libraries starts with a quick overview of the std::iostream library, continuing with
streams formatting examples, and examples of stream operations for: standard file streams, filebuf,
read-write, and string streams.
Starting with a quick overview of containers and their iterators, the chapter continues with containers,
then Algorithms, and closes with examples.
Chapter provides links for: C++ Patterns, declarative programming, templates, and a few other
"odds and ends".
Code Contents:
This repository holds narrative and code examples
used in the C++ story.
Note:
All of the code here has been implemented using Visual Studio, so each item below has a visual studio
project. Every one of them need the C++17 language option set. That should already be part of the
project settings, but if something fails to compile, please check the language option.
-
Chapter1-C++ Models
-
Chapter1-Structure
Demo with two components and an executive. One of the components provides an interface
and object factory.
-
Chapter1-MemoryModel
Illustrates use of static, stack, and heap memory. Also illustrates stack based resource
management.
-
Chapter1-Classes
Develops small point class and demonstrates it is a value type.
-
Chapter2-Survey
-
Chapter2-Survey
Mostly small examples used to support Chapter2 discussions:
Elementary examples of Arrays and Pointers, STL containers, new Optional type,
casts, and template function overloads.
-
Chapter2-overloading
Simple overloading demonstration that is repeated using std::optional type.
-
Chapter2-overriding
Uses SWDev, Dev, TeamLead, and ProjectMgr classes to demonstrate overriding.
-
Chapter2-Person
Class that models a person with stats properties.
-
Chapter3-Data
-
Chapter3-Data
Demonstratons of initialization, structured binding, float granularity
-
Chapter3-sizes
Uses displayType function to explore sizes of fundamental and library types.
-
Chapter3-init
Illustrates uniform initialization with many small examples.
-
Chapter3-STL (uses DirWalker)
Illustrates quickly building interesting data structures using the STL containers
and iterators.
-
Chapter4-Operations
-
Chapter4-QuickExample
Illustrates dispatching functions and callbacks
-
Chapter4-Coercion
Illustrates narrowing and numeric conversions of fundamental types
-
Chapter4-CopyOperations
demonstrates copy syntax and operation for fundamental types and structs
-
Chapter4-AssignmentOperations
demonstrates assignment syntax and operation for fundamental types and structs
-
Chapter4-functions
Illustrates functions, function pointers, methods, method pointers, functors,
and std::invoke.
-
Chapter4-CallableObjects
Illustrates functions, function pointers, methods, method pointers, functors,
and std::invoke. Similar to Chapter3-functions but with different examples.
-
Chapter4-Logger
Illustrates new logger design
-
Chapter4-ReturnValueOptimization
Demonstrates how and when RVO works.
-
Chapter4-STL
Demonstrates use of lambda with copy_if algorithm
-
Chapter5-Classes
-
Chapter5-QuickExample
Demonstrates tiny logger.
-
Chapter5-classes
Demonstrates three variations of a point class used to discuss class-related design.
Develops Anatomy class illustrating important class methods, e.g.
Copy and move construction, copy and move assignment, destructor, etc.
-
Chapter6-Class Relationships
-
Chapter6-QuickExample
Demonstrates extending existing classes through inheritance.
-
Chapter6-ClassLayout
Demonstrates how compound classes are layed out in memory.
-
Chapter6-Polymorphism
Shows how virtual methods are bound to a derived class instance when invoked using a
base class pointer or reference.
-
Chapter6-PeopleHierarchy
A thorough walkthrough of the use and behaviors of class hierarchies.
-
Chapter7-Templates
-
Chapter7-QuickExample
Demonstrates lazy translation of templates.
-
Chapter7-CodeFragments
Demonstrates class template specialization.
-
Chapter7-TemplateFunctions
Basic syntax demo with overload resolution example.
-
Chapter7-TemplateClasses
Basic syntax demo.
-
Chapter7-SFINAE
Illustrates template function overload resolution.
-
Chapter7-TemplateSpecialization
Logger with formatting and timer options.
-
Chapter7-TypeTransformation
Illustrates type transformations when passed as arguments to a function. Uses Boost::type_index.hpp.
-
Chapter8-Template Metaprogramming
-
Chapter8-QuickExample
Shows how to display a std::tuple.
-
Chapter8-Display
Developes very flexible functions for display using Template Metaprogramming. These were used
throughout the CppStory chapters to show the effects of code constructs. This project uses
custom type traits developed in Chapter7-TypeTraits (see below).
-
Chapter8-TemplateSpecialization
Uses constexpr if to simplify demo logger from Chapter 6.
-
Chapter8-VariadicFunctions
Presents several variadic function demonstrations.
-
Chapter8-VariadicMixins
Defines derived class that gracefully accepts any finite number of mixin base classes.
-
Chapter8-VariadicClassComp
Defines class that gracefully accepts any finite number of member type instances.
-
Chapter8-FoldExpression
Illustrates variadic folding over binary operators.
-
Chapter8-CustomTypeTraits
Illustrates simple construction of type traits. Will fail if user supplies template
arguments that have defaults.
-
Chapter8-TypeTraits
Demonstrates the construction of, with a bit more effort, very strong trait operations
that deal well with defaulted arguments.
-
Chapter9-Libraries
-
Chapter10-Streams
-
Chapter11-STL
-
Chapter11-STL_Demos
Demonstrates containers, iterators, and algorithms
-
Chapter11-ModifiedSTL_Demos
Demonstrates making STL code more readable by hiding iterators and more.
Build:
Built using Visual Studio Community addition - 2019, with C++17 option. Tested on Windows 10.
Status:
No planned additions.