Artima Weblogs | Christopher Diggins' Weblog | Discuss | Email | Print | Bloggers | Previous | Next
Sponsored Link •
I am working lately a lot on dynamic typing and functional programming in C++. I've recently hacked Kevlin Henney's cool boost::any type and introduced a variation, which allows referencing of values of any type without copying.
Recently I went in hacked up the boost::any type by Kevlin Henney for the OOTL. My variant is called ootl::Object but alongside of it is a new partner in crime called ootl::ObjectPtr. What ObjectPtr does is allow you to refer to just about any value-type without the overhead of a new operation.
The ObjectPtr implementation is a little tough to explain, and is based on the structural sub-typing mechanism I designed for my Interfaces proposal last year, and David Abraham's clever implementation which he posted on comp.std.c++. It essentially creates static function tables at compile-time, and stores a pointer to them along side the pointer to the value.
The code is posted at http://www.ootl.org/ootl/ootl_objects.hpp.htm, and some tests can be found at http://www.ootl.org/ootl/tests/ootl_test_objects.hpp.htm. I've tested the code using Visual C++ 7.1 and GCC 3.4. You can download the OOTL library ( which is now very compact because I have removed all references to Boost) at www.ootl.org
For those interested in the OOTL::ObjectPtr implementation, I recommend taking a look at the BIL Interfaces Library by Jonathan Turkanis. You can use his library to accomplish pretty much the same thing as follows:
BOOST_IDL_BEGIN(IObject) BOOST_IDL_END(IObject) typedef boost::manual_ptrJonathan's library obviously does a heck of a lot more, and explores deeply the possibilities inherent of structural subtyping. The only drawback of Jonathan's library (if you can call it that) is that it requires Boost.
PS. Coming up soon, things you can do with comma operator overloading and dynamic typing in C++, that your parents don't want you to know about.
Have an opinion? Readers have already posted 2 comments about this weblog entry. Why not add yours?
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
|Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.|