|
Thomas Becker's Free Software Utilities
|
Zephyr Associates, Inc., the company where I work, is always looking to hire exceptional C++ talent. If you can meet the highest expectations in terms of commercial software engineering in C++, and you would like to live in Tahoe, where software engineers go skiing during lunchbreak, then . |
Type Erasure for C++ IteratorsIn their book on C++ template metaprogramming, Dave Abrahams and Aleksey Gurtovoy define type erasure as "the process of turning a wide variety of types with a common interface into one type with that same interface."
Perhaps the most widely known and used example
of type erasure is
The variable The relevance of this in the context of object-oriented programming is that an interface can now say to the client programmer: "I need you to give me something that's callable as specified by this here function type. What it really is, I don't care. You can give me different things at run time. Also, you can change your client code so it gives me something other than it did before, and you won't have to recompile me." Or, referring to a return value rather than an argument, an interface could say: "I'll give you something that's callable as specified by this here function type. What it really is, you won't know. It could change at run time. I might also change it at compile time, but don't worry, you won't have to recompile because of that."
When working with C++ iterators, it is often desirable to design interfaces that take or return iterators
and have a similar "insensitivity" to the actual, concrete type. In other words, the interface may want to
say something like: "I need you to give me an iterator which is a forward iterator or better and which
dereferences to an
I have written a class template
The download below contains the
|
|
Download any_iterator
|
|
Revision HistoryMar 2008Implemented a workaround for the fact that boost::is_convertible<X, Y>::value
is false whenever X and Y are abstract base classes (including the
case where X equals Y).
Feb 2008
Sep 2007
Aug 2007
Jan 2007
Jun 2006 |
|