STEVE DEWHURST | C++


About Steve Contact Code About Semantics Publications Courses Phrenology of Semantics
About Steve
Steve Dewhurst

About Steve

Steve Dewhurst is the co-founder and president of Semantics Consulting, Inc. Steve is the author of numerous technical articles on C++ programming techniques and compiler design, is the author of the critically acclaimed books C++ Common Knowledge and C++ Gotchas, and is the co-author of Programming in C++. He is a frequent speaker at industry conferences, where his presentations are consistently among the most popular and highest rated.  He is also a member of the advisory board for The C++ Source, was programming track chair for the Embedded Systems Conference (ESC), and was a visiting scientist at the Software Engineering Institute (SEI) at Carnegie Mellon University.  Steve has mentored and consulted with C++ projects ranging in size from 1 to over 100 developers, in areas ranging from compiler design to embedded telecommunications to ecommerce to derivative securities trading.

As a Member of Technical Staff in the UNIX Development Laboratory at AT&T Bell Laboratories, Steve worked with Bjarne Stroustrup, the designer and first implementer of C++, on the first public release of the language and cfront C++ compiler, then served as the lead designer and implementer of the first non-cfront C++ compiler.  As a compiler architect at Glockenspiel, Ltd., he designed and implemented a second C++ compiler.

Steve was a contributing editor for The C/C++ User's Journal, a principal lecturer at The C++ Seminar, has served as a principal on the ANSI/ISO C++ standardization committee, was the C++ training series adviser for Technology Exchange Company (Addison-Wesley), was a member of the editorial board of and columnist for C++ Report, and was co-founder and member of the editorial board of The C++ Journal. He has taught extensively in both university and commercial settings.  He has also written C, COBOL, and Pascal compilers, was a principal on the ANSI/IEEE Pascal Standardization Committee, and a reviewer for ACM Computing Reviews.

Semantics Consulting, Inc. is located in the small New England town of Carver, Massachusetts. Like all small New England towns, Carver has a tradition of citizen involvement, and over the years Steve has been astonished to find himself harvesting cranberries, coaching the high school wrestling team, and serving on the town water commission, finance committee, and website committee.

Steve's LinkedIn Profile

Contact Information

  Semantics Consulting, Inc.
  52 Forest Street/Rural Route 5
  PO Box 997
  Carver, MA  02330
  USA

Telephone:  +1-508-866-9400
Email:  scd@semantics.org

Code

This page contains C++ code from a variety of sources:
  • Complete source for my "Common Knowledge" column that appeared in The C/C++ Users Journal or in CUJ's "Online Experts" forum.
  • Source that accompanied this site's (currently inactive) "Once, Weakly" web column.
  • Stuff I've been thinking about.
These facilities were developed primarily to illustrate C++ programming techniques, and are not necessarily generally useful (some are even kind of weird). Each set of files is fairly self-contained, and should not require anything more than the C++ standard library and a main function in order to run.  If a set of files contains a main.cpp file, then you should be able to produce an executable by copying the files to a directory and doing a CC *.cpp (or the local equivalent).

Contents

Type Dismantling

A framework for the dismantling, pattern matching/substitution, and regeneration of a type.  See a description of the framework in the Once, Weakly section of this site.
dismantle.h

Typelist Meta-Algorithms

Algorithms, meta-function objects, and meta-function object adapters for manipulating typelists.  See a decription of the techniques in the Once, Weakly section of this site.
This code has been updated, as described in another Once, Weakly
typelist.h
utils.h
metafunction.h
typlistalgorithms.h
main.cpp

Named Expanding Monostate protopattern

This is a technique in search of an application. See a description of the technique in the Once, Weakly section of this site.
expandingmonostate.cpp

Typeints

CUJ 21(6), June 2003: "N-Ary Nibbling"
Moving typeints from a binary representation to a 2**n representation in order to deal with compilers' restrictive template instantiation recursion depth limits.  Compile time arithmetic in excess of 5000-bit precision is possible.
typeint_nary.h
utils.h
main.cpp

CUJ 21(4), April 2003:  "Scouting Out an Optimization"
A detailed examination of a typeint multiplication algorithm, and discussion of metaprogramming techniques for improving its compile time.
typeint_mul.h
utils.h
main.cpp

CUJ 21(2), February 2003:  "Typeints"
This facility is the first version of a library that performs extended-precision compile time arithmetic using the type system instead of binary arithmetic.  Depending on the capabilities of the compiler, it's possible to perform compile time arithmetic on 1000-bit (or larger) integers.

The first set of files consists of a simple version of the typeint facility and a test program.
typeint.h
utils.h
main.cpp

The second set of files is a reimplementation of the typeof operator implementation (see below) using typeints to perform the extended-precision compile time arithmetic.
gengn.h
gentype.h
typeof.h
typeint.h
utils.h

Typeof

CUJ 20(8), August 2002:  "A Bit-Wise Typeof Operator, Part 1"
CUJ 20(10), October 2002:  "A Bit-Wise Typeof Operator, Part 2"
CUJ 20(12), December 2002:  "A Bit-Wise Typeof Operator, Part 3"
Here is the source code for the of the typeof implementation that translates a type into a Gödel number, then back to a type in order to implement most of the functionality of a built-in typeof operator.  It includes some elementary type manipulation utilities, the multi-integer compile time shift operations, the Gödel number generator, and the Gödel number to type regeneration.  The code is almost identical to that which appeared in the article, but has been factored somwhat to make it cleaner, and (secondarily) make it compile a little faster.
utils.h
multishift.h
gengn.h
gentype.h
typeof.h

CUJ 20(8), August 2002:  "A Bit-Wise Typeof Operator, Part 1"
There was a bug in one of the code examples.  I had this to say about it in the December, 2002 CUJ.

List

CUJ 20(6), June 2002:  "Running Circles Round You, Logically": List
List (great name!) is an STL-like container that uses two-way pointers to implement a singly-linked list that can change its mind as to which way it's organized.  Its iterators are similarly confused, and this makes for some interesting complexity results.
Note:  A problem with the use of ptrdiff_t to hold a pointer value has been fixed.  Use list2.h in preference to the original list.h.
Note 2:  See flist, below, for a better altenative to List.
list2.h

flist

flist is an STL-compliant version of List.  flist uses  2-way pointers to implement a container that has the same members and performance as std::list, but that uses half the working storage.  It also provides fickle-bidirectional iterators and a constant time reverse operation.
flist.h
flist documentation

MultiIn

CUJ 20(4), April 2002:  "Metaprogrammed Adapters": MultiIn
MultiIn is an input/forward iterator adapter that allows an unbounded number of differently-typed input/forward sequences to be treated as a single "supersequence," without copying the values from the constituent sequences.
multiin.h

MultiOut

CUJ 20(2), February 2002:  "Output Iterator Adapters": MultiOut
MultiOut is an output iterator adapter that allows an output sequence to be sent to an unbounded number of output streams simultaneously.
multiout.h

Books

C++ Common Knowledge C++ Gotchas Programming in C++

Articles

Dewhurst, S., Dougherty, C., Ito, Y., Keaton, D., Saks, D., Seacord, R. C., Svoboda, D., Taschner, C., & Togashi, K. Evaluation of CERT Secure Coding Rules through Integration with  Source Analysis Tools (CMU/SEI-2008-TR-014, ADA482285).  Carnegie Mellon University, Software Engineering Institute, 2008.

Dewhurst, S.C. Unfinished Business. C/C++ Users Journal Experts Forum, 21, 11 (November 2003).

______.  A Matter of Judgment. C/C++ Users Journal Experts Forum, 21, 10 (October 2003).

______. What Are You, Anyway? C/C++ Users Journal Experts Forum, 21, 8 (August 2003).

______. N-Ary Nibbling. C/C++ Users Journal Experts Forum, 21, 6 (June 2003).

______. C++ Gotchas #1 and #17. C/C++ Users Journal Online Exclusives, 21, 5 (May 2003).

______. Scouting Out Optimizations. C/C++ Users Journal Experts Forum, 21, 4 (April 2003).

______. Typeints. C/C++ Users Journal Experts Forum, 21, 2 (February 2003).

______. Two C++ Gotchas. C/C++ Users Journal, 21, 2 (February 2003).

______. A Bit-Wise Typeof Operator, Part 3. C/C++ Users Journal 20, 12 (December 2002).

______. A Bit-Wise Typeof Operator, Part 2. C/C++ Users Journal 20, 10 (October 2002).

______. A Bit-Wise Typeof Operator, Part 1. C/C++ Users Journal 20, 8 (August 2002).

______. Running Circles Round You, Logically. C/C++ Users Journal 20, 6 (June 2002).

______. Metaprogrammed Adapters. C/C++ Users Journal 20, 4 (April 2002).

______. Output Iterator Adapters. C/C++ Users Journal 20, 2 (February 2002).

______. Conventional Generic Algorithms. C/C++ Users Journal 19,12 (December 2001).

______. Stepping Back. C/C++ Users Journal 19,10 (October 2001).

______. One at a Time, Please. C/C++ Users Journal 19,8 (August 2001).

______. Split Idioms. C/C++ Users Journal 19, 6 (June 2001).

______. A Question of Respect. C/C++ Users Journal 19, 4 (April 2001).

______. Polymorphic Function Objects. C/C++ Users Journal 19,2 (February 2001).

______. Fungible Control Structures. C/C++ Users Journal 18,12 (December 2000).

______. Elemental Base Idioms. C++ Report 12, 7 (July/August 2000).

______. Don't Ask, Don't Tell. C++ Report 12, 5 (May 2000).

Dewhurst, S.C. Subobject members. C++ Report 5, 3 (March/April 1993).

______. Program philosophy checkers, active libraries, and devolution of the compiler. Paper accepted for workshop on Development Processes for Use of the Object Paradigm, OOPSLA, Vancouver, B.C., October 23, 1992.

______. Distributed abstract interfaces. C++ Report 4, 3 (March/April 1992) and in C++ Gems (ed. S.B. Lippman) SIGS Books, 1996.

______. Abstracting data abstraction. Invited paper, In Proceedings of the Borland Languages Conference, April 28-May 1, 1991.

______. Control abstraction. The C++ Journal 1, 2 (Fall 1990).

______. Little generics. The C++ Journal 1, 1 (Summer 1990).

Coplien, J., Dewhurst, S.C., and Koenig, A. C++: evolving toward a more powerful language. The AT&T Technical Journal 67, 4 (July/August 1989).

Dewhurst, S.C. The architecture of a C++ compiler. Invited paper, In Proceedings of the USENIX C++ Workshop, Santa Fe, New Mexico, November 9-10, 1987.

______. Flexible symbol table structures for compiling C++. Software - Practice and Experience 17, 8 (August 1987).

______. Object representation of scope during translation. In Proceedings of the 1st European Conference on Object-Oriented Programming, Paris, France, June 15-17, 1987 and in Lecture Notes in Computer Science #276, Springer-Verlag, 1987.

Dewhurst, S.C. and Stark, K.T. Out of the C world comes C++. Computer Language 4, 5 (February 1987).

Dewhurst, S.C. Automatic generation of syntax-directed editors: a grammar-independent implementation combining tree-structured and screen editing capabilities. Master of Science in Engineering thesis, Princeton University (January 1982).

______. An equivalence result for temporal logic. ACM SIGPLAN Notices 16, 2 (February 1981).

Talks

Steve has given hundreds of talks, seminars, and webinars at industry conferences and and other venues. Some recent presentations include:

Temporal Partitioning of Semantics in C++ Design.
Bloomberg LLP Distinguished Speaker Series (invited talk, 10/2014).

Protopatterns that Fizzled: Three interesting design patterns that got left in the bit bucket.
Bloomberg LLP Distinguished Speaker Series (invited talk, 3/2013).

Undercover C++: What's efficient and what isn't.
Design East (conference presentation, 10/2012).

Welcome Visitors.
Citadel LLP, Citadel Tech Talks Program (webinar, 9/2012)

Writing Efficient, Self-Maintaining Code With C++ Templates.
Design West (conference presentation, 3/2012).

C++ and Sociology.
Bloomberg LLP (new hire motivational talk, 12/2009).

Once, Weakly

Please note that this "Once, Weakly" feature is either on hold or discontinued depending on your level of optimism.  This link has been reestablished by popular demand.

Note: the items on "C++ommon Knowledge" that appeared in this space between April and August of 2004 are now available as C++ Common Knowledge:  Essential Intermediate Programming.

21 February 2004:  Typelist Meta-Algorithm Implementation Tricks

We examine a few more typelist meta-algorithms to motivate a few somewhat half-baked metaprogramming techniques used to implement them. (That’s why I’m calling them “tricks” instead of something more pretentious, like “strategies.”)

23 December 2003:  Checked Bridge Protopattern

A (proto)pattern that allows different versions of Bridge interfaces and implementations to work together. When the Bridge pattern is used with different versions of software that are distributed at different times, it is often the case that the interface part of the Bridge may be paired with an implementation part that was developed for an earlier or later version of the interface.  The Checked Bridge pattern shows how to export the implementation requirements of an interface to potential implementations, and perform a fine-grain capability query to ensure that a particular aspect of an interface’s functionality is supported by its implementation.

9 September 2003:  Typelist Meta-Algorithms

How to perform compile time partition, sorting, and transform of typelists, with accompanying meta-predicates, meta-comparitors, and meta-function object adapters.

1 April 2003:  A Matter of Judgement

I defend myself against the forces of zealotry.  Along the way we discuss using non-standard switches to implement coroutines and playing with dolls.

18 March 2003:  Introduction to Traits

An introduction to a basic template programming technique.

11 March 2003:  What Are You, Anyway?

We look at one of the more obsure syntactic problems of template programming:  how to guide the compiler's parse when there is not enough information available for the compiler to do the job on its own.  Along the way we discuss and disambiguate the "rebind" mechanism employed by the standard containers.

3 March 2003:  Attack of the Clones

This item looks at the utility of implementing a "clone" operation on a hierarchy, and discusses its implications for designing frameworks and ordering a meal in a Swedish restaurant.

1 March 2003:  A Problem in Coordination

This item looks at a problem in class template instantiation interface design that plays off safety versus flexibility.

23 February 2003:  You Dis'n Me?

We discuss design of a framework for the dismantling of an arbitrary type into its component parts, and its later regeneration for the purpose of compile time type manipulation.  We also show how to extend the framework to include arbitrarily fine detail on type-related information.  We then show how some simple pattern matching and substitution and replacement can be performed on a dismantled type before a normal type is regenerated from it.   In effect, we now have two equivalent, but structurally distinct, versions of the same type.  The normal version is optimized for use in a traditional fashion: accessing its operations, causing code to be generated that will execute at runtime, etc.  The dismantled version is optimized for compile time analysis and manipulation.  Therefore, we now have the ability to move an arbitrary type between representations according to how we want to use it.  The invertibility of the representations assures us that either representation will contain all the information present in the other.

6 January 2003:  Template Dismantling

It's not uncommon in template metaprogramming to dismantle a type into its component parts and put it back together differently.  In this episode, we'll do the same thing with types that are generated from templates.  We'll first show how to determine whether a given type was generated from a template.  Then we'll see how to work back from the instantiated type to the individual components of its instantiation (including the instantiated template itself), mix them up, replace them, tweak them, and produce a new type.

3 January 2003:  Unrolling Expertise

We discuss the use of template metaprogramming to improve efficiency while keeping the users of our facility in happy ignorance of what's going on behind the scenes. Along the way we'll look at properly general generic algorithms, automated loop unrolling, algorithm selection based on whether arguments are integer constant-expressions, and the beneficial aspects of ignorance.

6 December 2002:  Type Structures

We examine the use of "type-structures" as a compile time analog of runtime data structures. We discuss how to construct and manipulate at compile time simple lists of integers, function pointers, types, and templates.

24 November 2002:  SFINAE Sono Buoni

We examine the concept of SFINAE (substitution failure is not an error). This fairly straightforward language feature, whose intended use is to facilitate function template argument deduction, has some rather surprisingly effective applications in template metaprogramming.

6 November 2002:  Expanding Monostate Protopattern

We discuss the use of a template member function in a non-template class to implement an extended version of the Monostate pattern.  This version of Monostate allows the seamless addition and removal of Monostate members (at compile time) simply by referencing them.

Note: the items on C++ gotchas that appeared in this space prior to November 2002 are now available in book form as C++ Gotchas.

Courses

We offer training in

  • Advanced C++
  • Embedded C++
  • Design Patterns in the C++ Context
  • The Standard Template Library
  • C++ Templates and Template Programming Techniques
  • C++ Common Knowledge
  • Intermediate and Introductory C++

About Semantics

Semantics Consulting, Inc. is a fully insured, type C Massachusetts corporation.  We've been training and consulting since 1993, initially as Stephen C. Dewhurst DBA Semantics.  We've been incorporated since 1997.

In order to provide a wider variety of high-quality course material and instruction, Semantics is now partnering with Saks and Associates. If you would like to schedule Steve for training, a lecture, or consultation, please contact Saks and Associates.

bool Postorder::next() {
   switch( pc )
   case START:
   while( true )
      if( !lchild() ) {
         pc = LEAF;
         return true;
   case LEAF:
         while( true )
            if( sibling() )
               break;
            else
               if( parent() ) {
                  pc = INNER;
                  return true;
   case INNER:    ;
               }
               else {
                  pc = DONE;
   case DONE:     return false;
               }
      }
}