Lecture #7 - Template Policies and Traits

Web Resources:

CppReference.com, CPlusPlus.com, C++ TechLinks
Going Native 2013 - many experts
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

Content:

This lecture covers template template policies and template traits. We will continue discussing the HashTable example.
  1. Notice:

    Two former students, now working at FaceBook, will be interviewing during the Career Fair, Feb 2nd.
    They will have an information meeting, directed especially at students from my classes:
    FaceBook Information Meeting
    11:00 am in LSB 001, Wednesday, February 1st
    If you are interested in either an internship or permanent employment, you will be welcome.
  2. Readings for Lecture #7

    Text: Study chapter 16 carefully
    Project #1
    Templates, Templates Presentation, ppt
  3. Glossary of Terms

    • Template:
      A function or class whose declaration includes one or more unspecified type parameters.
      Templates allow us to write one function or class that use more than one type. The specific type isn't specified until an application instantiates it with a type suited for the application.
  4. Syllabus
    Describes topics to be covered, reading material for you to digest before coming to class, and due dates for the assigned projects.
  5. We are using Piazza for Q&A help. You will find the Piazza site here http://piazza.com/syr/spring2017/cse687.
  6. Projects:

    Resources for Project #1:
    Project #1 statement, Project1HelpS17
    NoSql Database

    Resources for Project #2:
    Project #2 statement, Project2HelpS17
    Type-based dependency analysis

    • Here is a link that has a nice description of the original Tarjan algorithm
      for finding strong components, my favorite:
      DFS and Strong Components.

    C++ Survival Guide, doc
    Visual Studio help notes, doc
    Code Analyzer, Project Properties
    Project Submissions

    Policy for due date extensions - only for certified illness and work or interview trips out of town:
    one week extension, with proof. Only one extension per project.
  7. Templates Presentation
    Templates are one of the terrific features of the C++ language. They are the basis of the Standard Template Library (STL) and are useful in day-to-day programming.
  8. small template examples
  9. More Template Examples:

    Examples of template details including some STL Template-based Containers
    Illustrates use of algorithms, vectors, lists, sets, and maps.

    Note: Pay special attention to projects named:
    issue1, issue2, issue3a, issue3b, issue4, PredicateFunctors, and UnaryFunctions
  10. Hashtables

    HashTable Project
    HashTables are fundamental and very useful data structures. At this time there are no hash-based containers in the STL. So here is my implementation - it's a good example of the use of templates.

    Design of Containers with Iterators, ppt
    Look at HashTable<key,value,Hash> and HashIterator<key,value,Hash> classes. Draw some fairly general conclusions.

    Template Policies and Traits, ppt, Important
    Discusses policies and traits in the context of our HashTable project.

  11. Even more template examples!

    Template TechniquesImportant
    Template members, template template parameters, partial template specialization and more...

    STL Containers
    Demonstrates almost all of the STL Containers with simple example code.

    Functor examples
    Functors are classes that define operator() - their syntax is similar to functions, but they are more powerful. The STL uses functors to support many of the algorithms defined on containers.

    Callable "Objects"
    Callable "Objects" are any of the following: function, method, functor, or lambda.

    Lambda capture
    Lambdas have a very useful data capture mechanism that is illustrated in this demo.

    Smart Pointers with Reference Counting
    Smart pointers are useful tools, especially for holding onto heap resources indexted through an STL container. They are also a great illustration of many of the Template Techniques we've discussed in this course.

    Template MetaProgramming
    We will peek into this demo code for one or two small examples, leaving the rest for later in the semester.

  12. Inheritance Demo code, Inheritance Demo Sharing, vsdx
  13. const pointers
  14. Software design presentations:

    Software Design Goals
    Design Goals and Attributes - used to measure designs.

    Design Strategies
    Discusses styles of design and binding.

    Design Guidelines
    Small principles and useful techniques

    Design Issues
    Practical issues and problems of design and implementation

  15. Namespaces:

    Namespaces
    Basic information about how namespaces work. We will discuss why you want to use them.

    Composite Namespaces
    Demonstrates nested, sequenced, and extended namespaces.

  16. These are the most important items from today's lecture:

    Template Policies and TraitsImportant
    Discusses policies and traits in the context of our HashTable project.

    Template TechniquesImportant
    Template members, template template parameters, partial template specialization and more...

    STL Containers
    Demonstrates almost all of the STL Containers with simple example code.

    Functor examples
    Functors are classes that define operator() - their syntax is similar to functions, but they are more powerful. The STL uses functors to support many of the algorithms defined on containers.

CST strip