Due to popular demand and a certain amount of kvetching, I've
reestablished a link to the (currently inactive) Once, Weakly column
on semantics.org.
This is the place to find articles on
SFINAE
typlist meta-algorithms
the Checked Bridge and Expanding Monostate protopatterns
type dismantling and regeneration framework
to which I've referred in recent conference talks and courses.
SD Best Practices in Boston is being held the week of September 11th.
Please see <http://www.sdexpo.com/> for conference details.
I'll be giving five talks:
Tuesday, 8:30am: High-Level Coding in C++
Abstract:
This talk discusses how code can be written in modern C++ to minimize
error and maximize programmer productivity without sacrificing (and
typically improving) speed. In particular, we'll examine how to
reduce or eliminate use of arrays, pointers, loops, and the
if-statement.
Tuesday, 1:45 pm: Do You Copy?
Abstract:
What everyone should know about C++ copy operations; idioms,
mechanics, and common errors. We also discuss the closely related
areas of direct vs. copy initialization semantics, the return value
optimizations, copy-like member template operations, and effective
swap implementations.
Wednesday, 3:45pm: Mechanics and Applications of Class Template
Partial Specialization
Abstract:
Class template partial specialization is a straightforward C++
language feature that is vastly underused. This talk covers the
basics of partial specialization mechanics and shows how the feature
may be used in straightforward ways to customize code based on
statically-available information. We'll also show how the feature
may be used in less obvious ways to supplant and simplify function
template overloading, extract information about types, uninstantiate
templates, and rebind allocators without using the rebind mechanism.
Thursday, 8:30am: Welcome Visitors
Abstract:
Does the Visitor pattern have you stumped or just annoyed? This class
will take you through the standard GOF Visitor, Robert Martin's
Acyclic Visitor, and Andrei Alexandrescu's ad hoc Visitor. By the end
of the class, you and Visitor will come to understand and respect each
other.
Thursday, 1:45pm: C++ Hierarchy Design Idioms
Abstract:
While C++ itself has relatively few rules on how the language may be
employed, the community of competent C++ programmers employs a large
set of implicit design and coding idioms. This class examines a
number of generally accepted low and mid level design idioms for class
hierarchies. We'll cover base and derived classes, coding for
polymorphism and safety, and the interplay of various design forces on
the eventual shape of the hierarchy.
flist is now documented! I've posted documentation on Semantics
Consulting's code page, along with the most current version of flist
at <http://www.semantics.org/code.html#flist>. (The documentation is
built on the original SGI html documentation, so you may encounter
some broken links if you delve too deep.)
Major changes include:
1) Addition of slist-like functionality, including insert_after,
erase_after, splice_after, and previous.
2) Change of name of the isplice members to splice_before.
Best regards,
Steve
A while back I published an article in the (late, much missed) CUJ
describing a List container that used two-way pointers to implement an
STL-like container with "fickle-forward" iterators. The primary goal
of that article was to illustrate the continued value of bitwise
operators in advanced C++ programming.
However, I've been thinking about List and its weird iterators on and
off since then. As an exercise for my advanced STL course, I decided
to turn List into a fully-compliant STL container. The results were
pleasing:
The new container is called "flist," which is pronounced "ef list."
The "f" stands for "fickle."
flist has the same functionality as std::list (splice, merge, sort,
remove_if, etc.)
flist uses half the working storage of std::list, with equivalent
performance. This implementation of flist also seems to cause less
code bloat than (at least some implementations of) std::list for many
instantiations with different element types.
flist has "fickle-bidirectional" iterators that can easily change
their mind about which way they're traversing. (It also has
reverse_iterators, but they have different properties.)
flist has a constant-time reverse operation.
The major functional difference between std::list and flist is in
iterator invalidation. flist is not a "node-based" container (even
though it's implemented with nodes) because inserting or erasing an
element may affect iterators to adjacent elements. However, like
std::deque, pointers and references to adjacent elements are unaffected.
The source code for flist may be found on Semantics Consulting's code
page: <http://www.semantics.org/code.html#flist>. Comments at the
head of the file give more information about the container, and I hope
to have documentation and usage examples available soon.
Steve
I'll be giving a talk on "Class Hierarchy Design Idioms in C++" for
the Silicon Valley chapter of the ACCU the evening of Wednesday, May
24th. (For details, see <http://www.accu-usa.org/>.)
I'm told I may also be asked discuss my experiences in writing and
publishing. If given half a chance, I may also stray into a
discussion of approaches to compile time type dismantling and
regeneration (similar to
http://www.semantics.org/once_weakly/w06_typedismantling.pdf).
Best regards,
Steve
This week, C++ommon Knowledge attempts to discuss old and new style
casting in an evenhanded and nonjudgmental way. With partial success.
Actually, we come down rather heavily on the side of the new cast
operators. And say disparaging things about old style casts. But we
made a token attempt to be open minded.
New Cast Operators
http://www.semantics.org/once_weakly/ck51_newcast.pdf
All the C++ommon Knowledge articles are available at
<http://www.semantics.org/weekly.html>.
Best regards,
Steve
...and a big round of applause for Chuck Allison, august former senior
editor of the C/C++ Users Journal for teaming up with Bill Venners to
launch a much needed new C++ publication! See
http://www.artima.com/weblogs/viewpost.jsp?thread=56159
for an intro, and
http://www.artima.com/cppsource/
for the zine itself. Your correspondent (that's me) is involved with
the zine in a modest way as a non-august member of its advisory board.
Best regards,
Steve
...and a big round of applause for Chuck Allison, august former senior
editor of the C/C++ Users Journal for teaming up with Bill Venners to
launch a much needed new C++ publication! See
http://www.artima.com/weblogs/viewpost.jsp?thread=56159
for an intro, and
http://www.artima.com/cppsource/
for the zine itself. Your correspondent (that's me) is involved with
the zine in a modest way as a non-august member of its advisory board.
Best regards,
Steve
This week features an eclectic set of topics on problematic array
arguments, useless keywords, the semantics of comparing class pointers,
and the mechanics of capability queries. See
http://www.semantics.org/weekly.html
Enjoy!
Steve
A Little Polish
===============
Yes, the rumors are true! C++ Gotchas is now available in Polish! See
http://helion.pl/ksiazki/cppkru.htm
C++ Common Knowledge
====================
Once, Weakly is taking a new tack.
When he took over the editorship of the late C++ Report, Herb Sutter
asked me to write a column on a topic of my choosing. I agreed, and I
chose to call the column "Common Knowledge." It was supposed to be, in
Herb's words, "...a regular summary of basic lore that every working C++
programmer should know--but can't always." Alas, after a couple of
columns in that vein I became interested in template metaprogramming
techniques, and the topics treated in Common Knowledge from that point
on were very far from common.
However, the problem in the C++ programming industry that motivated my
original choice of column remains. I commonly encounter the following
types of individuals in my training and consulting work:
-- Domain experts who are expert C programmers, but who have only basic
knowledge of (and perhaps some animosity towards) C++
-- Talented new hires direct from university who have an academic
appreciation for the C++ language, but little production C++ experience
-- Expert Java programmers who have little C++ experience, and who have
a tendency to program in C++ the way one would program in Java
-- C++ programmers with several years of experience maintaining existing
C++ applications, but who have not been challenged to learn anything
beyond the basics required for maintenance
I want to be immediately productive, but many of the people with whom
I'm working or who I'm training require preliminary education in various
C++ language features, patterns, and coding techniques before we can get
down to business. Worse, I suspect that most C++ code is being written
by individuals like these, and is therefore not what most C++ experts
would consider to be production quality. (Yes, that was an understatement.)
These new Once, Weakly articles are designed to address this pervasive
problem by providing essential, common knowledge that every professional
C++ programmer needs to know, in a form that is pared to its essentials
and that can be efficiently and accurately absorbed.
...
See the rest of this introduction to C++ommon Knowledge at
http://www.semantics.org/once_weakly/ck00_intro.pdf
and the new C++ommon Knowledge Once, Weakly articles at
http://www.semantics.org/weekly.html
Best regards,
Steve
Software Development West, Santa Clara, March 15-19
-------------------------
Just a reminder that I'll be at SD from mid-afternoon on Tuesday through
Friday. If you want to meet up for a chat, just catch me after one of
my talks (http://www.cmpevents.com/SDw/a.asp?option=G&V=3&id=197811).
Book Signing
-------------------------
I'll be signing copies of "C++ Gotchas" for Grove Books at SD, Wednesday
at 5pm (coincidentally just after my "gotchas" talk). Chances are,
after giving three talks in a row on Wednesday, I'll sign almost
anything that's put in front of me.
Article Archive
-------------------------
In response to too many requests for a copy of "Running Circles Round
You, Logically" and other articles that are not available online, I've
established an online article archive that provides access to most of my
articles. See http://www.semantics.org/localarchive.html or follow the
link from the "Publications" page of the Semantics site
(http://www.semantics.org).
Best regards,
Steve
In the current "Once, Weakly," 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.") See
http://www.semantics.org/weekly.html
The implementations of the following algorithms (and a simple test
driver) are available at
http://www.semantics.org/code.html#typelist_meta_algorithms
Best regards,
Steve
Algorithms
==========
Find
FindIf
Count
CountIf
Unique
UniqueEquiv
Transform
Transform2
TransformIf
EraseIf
Sort
Rotate
RotateN
MinElement
MaxElement
EqualIf
EqualSame
FillN
Replace
ReplaceIf
Merge
SetUnionEquiv
SetUnion
SetIntersection
SetDifference
SetSymmetricDifferece
Software Development West (http://www.sdexpo.com) will be held in Santa
Clara, March 15-19. I'll be giving seven talks, three of which are
completely new, three of which are completely updated versions of talks
I've given previously, and one of which is back by popular demand.
I hope to see you there!
Best regards,
Steve
====== ABSTRACTS ======
Practical Design Patterns in C++, Parts 1 and 2 <=== NEW MATERIAL!
----
These talks provide an introduction to the concept and use of design
patterns in the C++ context. While we do introduce the student to some
of the concepts that underlie design patterns, most of our time is spent
in highly practical examination of specific design patterns as
implemented in the C++ language. The classes include sections that show
how to employ patterns in combination to solve sophisticated design
problems, and advice as to how to select among available patterns in a
specific context. The course also covers many of the lesser known
features of the C++ language and C++ programming techniques and idioms
that are of practical importance when applying the patterns.
Typelist Meta-Algorithms <=== NEW TALK!
----
We give a brief introduction to typelists, a common mechanism for
creating and manipulating lists of types for compile time manipulation.
We then show how a typelist may be used to generate type-based
conditional code in a maintainable way. This in turn motivates
development of a suite of STL-like typelist meta-algorithms,
meta-function objects, and meta-function adapters. We'll finish up by
looking at sample applications of typelist meta-algorithms.
Clueing in the Compiler <=== NEW TALK!
----
Ever wonder exactly what the standards committee was thinking when they
added the typename keyword to the C++ language? This talk discusses
just how ignorant the compiler can be when translating template code,
and why and when seemingly unnecessary uses of typename and template are
required. Along the way we'll examine a version of the Monostate
pattern that allows the seamless addition and removal of Monostate
members (at compile time) simply by referencing them, and elucidate the
syntactically challenging "rebind" mechanism of the standard STL
container allocators. As a parting shot, we'll show how to use template
un-instantiation to avoid the rebind mechanism entirely.
C++ Gotchas <=== NEW MATERIAL!
----
What will it be this time? Low-level coding errors? Mis-use of idiom?
Failure to defend one's code against summer interns? All of the
above? This talk will expose a collection of new and old C++ gotchas
and discuss how they can be avoided or corrected.
Welcome Visitors <=== NEW TALK!
----
Does the Visitor pattern have you stumped or just annoyed? This talk
will take you through the standard GOF Visitor, Robert Martin's Acyclic
Visitor, and Andrei Alexandrescu's ad hoc Visitor. By the end of the
talk, you and Visitor will come to understand and respect each other.
C++ Hierarchy Design Idioms <=== OLD STANDARD...
----
While C++ itself has relatively few rules on how the language may be
employed, the community of competent C++ programmers employs a large set
of implicit design and coding idioms. This class examines a number of
generally accepted low and mid level design idioms for class
hierarchies. We'll cover base and derived classes, coding for
polymorphism and safety, and the interplay of various design forces on
the eventual shape of the hierarchy.
What better way to end the year than with a discussion of design patterns?
Once, Weakly: Checked Bridge
--------------
Checked Bridge is 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.
See the "Once, Weakly" for 23 December at
http://www.semantics.org/weekly.html
New Version of Practical Design Patterns in C++
-----------------------------------------------
The tried-and-true patterns course has been extensively revised to include:
1) additional non-GOF patterns
2) integration of C++ template programming techniques in pattern application
3) additional material on how to choose the "right" pattern
4) compound patterns and pattern languages
5) an entirely new section on Alexandrescu's policy-based design
See a full course description at
http://www.semantics.org/courses/patternsincpp.html
The Tyr library is an outgrowth of the code that accompanied my "Common
Knowledge" C/C++ Users Journal columns and this site's "Once, Weakly"
web column. Eventually, the complexity and redundancy of maintaining
totally separate applications became annoying enough to force me to
consider establishing a somewhat more standard environment. Because
each new functionality tended to depend to a large degree on existing
functionalities, it seemed to make sense to package the code as a library.
The current library is basically a repackaging of most of the existing
code at http://www.semantics.org/code.html (Though those familiar with
the existing code may notice some metaprogrammed upgrades to earlier
items, and a bugfix or two.)
Like the better-known Loki (see http://www.moderncppdesign.com), Tyr is
one of those Norse gods who pop up so often in C++ library design. Tyr,
sometimes known as Tiw (whence Tuesday), lost his right hand to Loki's
son (who happened to be a wolf), Fenrir. (I think it might be Tiw much
to try to draw any conclusions about the relationship of these
respective C++ libraries from the myth.) In any case, unlike Loki, Tyr
has many fine personal qualities, which explains why Loki is bound to a
rock in a cave, and Tyr isn't. But that's another story...
In order to avoid misleading anyone about the current quality of the
implementation, this first release of Tyr is numbered 0.5, and is
available at http://www.semantics.org/tyr.html
Best regards,
Steve
--
Stephen C. Dewhurst Semantics Consulting, Inc.
508-866-9400 phone PO Box 997
508-866-9401 fax Carver, MA 02330
scd@...http://www.semantics.org
The last installment of my C/C++ Users' Journal "Common Knowledge"
column is now available on the CUJ Online Experts Forum at
http://www.cuj.com/documents/s=8906/cujexp0311dewhurst/
Unfinished Business
-------------------
All good things must come to an end and so, coincidentally, must this
column. In this last installment of Common Knowledge we'll look at
combining some template metaprogramming odds and ends that have been
kicking around in my "to think about sometime" folder to see if we can
come up with a reasonable framework for ad hoc type manipulation. We'll
fail, but it'll be fun to make the attempt. Along the way we'll consider
the creative use of rocks in automotive maintenance, type translation to
facilitate compile-time manipulation, un-instantiation of class
templates, giving the STL allocator "rebind" mechanism the boot,
typelist meta-generic algorithms, meta-predicate adaptation, and the
importance of having fun.
____________________________________
New Once, Weakly: Typelist Meta-Algorithms
The latest edition of Once, Weakly applies the STL formalism to the
manipulation of typelists. We develop algortithms to partition, sort,
and transform typelists (at compile time), using appropriate
meta-predicates and meta-comparators. We also demonstrate how to write
meta-function adapters that allow the modification and composition of
meta-predicates and comparators. See
http://www.semantics.org/weekly.html. Source code for the typelist
meta-algorithms and adapters is available at
http://www.semantics.org/code.html.
_______________________
C++ Gotchas in Hungarian!
C++ Gotchas is now available in Hungarian from Kiskapu! My
Hungarian/C++ expert (who chooses to remain anonymous) has told me that
title should have been translated as "C++ csapdák" (Traps of C++) rather
than "C++ hibaelhárító" (C++ Troubleshooter), but I'm quite pleased with
the book's appearance and sheer volume of diacritical marks. Read more
about it (in Hungarian) at
http://www.kiskapu.hu/main.php?SHOW_BODY=termekinfo&TERMEKINFO_ID=121665401.
Best regards,
Steve