C C T B H P N

Lecture #27 - Template Metaprogramming

Weird examples

Web Resources:

CppCon - 2014, Going Native 2013
Herb Sutter's Blog, Herb Sutter on C++11, Herb Sutter keynote - Going Native 2012
Scott Meyer's Blog, S.M. on thread suspension, S.M.: C++11 Sampler
Stroustrup's Home Page
Code Project, Boost Library
Excellent C++ Q&A, Excellent reference - CppReference.com, CPlusPlus.com, C++ TechLinks

Content:

In this lecture we continue a discussion of template metaprogramming.
  1. Syllabus
    Describes topics to be covered, reading material for you to digest before coming to class, and due dates for the assigned projects.
  2. Project #3 Grades

    Project #3 Grades Chart
  3. Projects:

    Project #3 - Code Publisher Client Project3HelpS2019 - includes:
    Client-Channel-Server Diagram
    Diagram showing use ofC++\CLI translater between WPF (C#) GUI and C++ Comm Channel. Prototype GUI for Project #3
    Demonstrating Requirements with a GUI
    The projects, below, are intended to help with Project #4. They are included so we can peek ahead to see where we need to go with Project #4. Project4Help WPF
    Illustrates techniques used for WPF to use Comm via C++\CLI. Prototype GUI for Project #3
    Uses C++\CLI translator to interoperate with C++ Comm to navigate a remote directory tree.
    Project #4 - Remote Code Page Management Project4HelpS2019 - includes: Client-Channel-Server Diagram
    Diagram showing use ofC++\CLI translater between WPF (C#) GUI and C++ Comm Channel. Interop Help Demo class diagram, Interop Help Demo code
    Shows how to implement interoperation between C# and C++ as simply as practical. Creating C++\CLI Projects, pptx
    Mock Channel block diagram, Mock Channel
    Illustrates how to use .Net threads in a managed layer and C++ threads in a native layer. Communication Channel Structure
    Diagrams that show how asynchronous message passing communication works. Communication Channel Class Diagram
    Class diagram of our protype communication channel. Communication Channel Activities
    Activity diagram showing message flow through the communcation channel. CppCommWithFileXfer - Communication Channel Code
    Here's code you can use to implement message-passing communication. Project4HelpWPF code demo
    A getting-started GUI prototype that shows one way to build a client for Project #4. C++ Repository with WPF GUI - code demo
    This demo illustrates use of User Controls as well as remote directory navigation.
  4. Preliminaries:

    Program Scope and global data
    Scope inclusion rules

    Programming Languages, vsdx
    History of imperative, functional, and scripting langugages.
  5. Template Metaprogramming

    Template metaprogramming is the process of writing code for its compile-time effects in addition to its run-time behavior. Template metaprograms run at compile-time to produce often interesting template functions and classes. We will look at some examples today. Template metaprograms are often written for one of these reasons:
    • perform computation at compile-time instead of during execution.
    • introduce functionality that could not be achieved by run-time programs alone.
    • provide useful constructs for other (meta)programs, e.g., building metaprogramming tools.
    Template Metaprogramming
    Template Preliminaries:
    Template Members
    Typename qualifier
    Non-Template Template Parameter
    Template Template Parameter
    Partial Template Specialization
    Motivation for Partial Template Specialization
    The beginnings:
    Curiously Recurring Template Pattern (CRTP)
    Invoker - almost a delegate
    Test Types
    Coming soon: optional<T>
    What Template Metaprogramming can do:
    Binary Conversion at compile time
    compile time functions
    compile time loops
    compile time selection
    compile time switch case
    compile time type lists
    compile time lists improved
    Variadic Templates Variatic templates produce functions that can take an unspecified finite number of arguments and template classes that accept an unspecified finite number of template arguments. These demo programs try to show why that could be useful.
  6. Where do we go from here?

    How do you continue to strengthen your design and programming skills, and specifically, your C++ skills?
  7. C++11 - The current standard is C++17 - C++11 embodies the biggest changes:

    C++ Reference - includes C++11, 14, and 17

    What is C++11?
    A guide to Lambdas
    Local, anonymous function definition
    Move semantics and rvalue references
    Pass by value and return by value doesn't need to make copies
    make_shared
    Don't need delete if you use make_shared smart pointer.
    Type Inference
    Type declaration using auto that adopts the type of an expression result.
    Range-based for loops
    C++11 Thread support
    std::Thread documentation.
    C++ 11 std::async
    Clean semantics for calling a function asynchronously.

  8. C++11 - Code Examples and Tutorial Videos and Discussions:

  9. More C++11 Videos and Blogs:

    Herb Sutter on C++11
    Outstanding presentation on the things you can do better with C++11.

    C++ and Beyond
    Herb Sutter's talk on lambdas
    Herb Sutter's C++ and Beyond 2011 talk
    Herb Sutter's Effective Concurrency series
    Herb Sutter on Concurrency

    Herb Sutter's talk at PDC05 - skip the animations install
    This is an outstanding discussion of new features planned for C++ wrapped in an amazing discussion of concurrency.
    Slides from Herb Sutter's talk at PDC05

  10. Advanced C++ Texts

  11. Common C++ Problems, pptx
  12. Fragile Designs, pptx
  13. UML Notation Revisited pptx
  14. Go Programming Language:

    Code Folder
    hello.go
    echo.go
    variables.go
    composites.go
    Controls.go
    functions.go
    types.go
    interfaces.go
    testPkg.go
    utils.go
  15. Thinking about Software Design:

    Software Design Blog
    Summary of fundamental ideas. Object Oriented Design Blog
    Essential features of Object Oriented Design. Software Design Principles
    SRP, LSP, OCP, DIP, and ISP Software Design, ppt
    Broad survey of ideas with examples Design Strategies, pptx
    Summarizes design issues for modules and classes. Design Guidelines, pptx
    Design rules and idioms that transcend Object Oriented Design.

CST strip