----- Original Message ----- From: "Alex Martelli" email@example.com
I was thinking of the use of template specialization to describe the relationship of a type to a library, e.g. specialization of std::iterator_traitslibA::some_class by libB, which makes libA::some_class available for use as an iterator with the standard
(assuming it has some appropriate interface).
That requires proper design for extensibility in advance -- the standard library must have had the forethought to define, and use everywhere appropriate, std::iterator_traits, AND libA must expose classes that can be plugged into that "slot".
As I tried indicating, if you're willing to require design-in-advance for such issues, PEP 246 (together with Python's general mechanisms) already offer what you need.
Yes, factories and such creational patterns ARE a better long-term answer, BUT there's no denying that Ruby's ability to patch things up with duct tape (while having its own costs, of course!-) can be a short-term lifesaver. "If God had WANTED us to get things right the first time he wouldn't have created duct tape", after all:-).
In Alaska, where my wife grew up, they call it "100-mile-an-hour tape" -- good for any use up to 100 mph. [apparently not for ducts, though, even if they're sitting still :(]
Only Haskell's typeclass, AFAIK, has (among widely used languages and objectmodels) a smooth way to allow noninvasive 3rd party post-facto adaptation (and another couple of small gems too), but I guess it has
easier life because it's compile-time rather than runtime.
IIUC the same kind of thing can be implemented in C++ templates, if you know where to look. There's been a lot of discussion of how to build variant types lately.
I don't think you can do it without some degree of design forethought, but admittedly I'm starting to get very slightly rusty (haven't designed
dazzling new C++ template in almost six months, after all:-).
Well, I have to admit that I don't have the time to say anything backed up by any research at this point ...I'm currently stuck in a Microsoft gravity well trying to survive the descent... but thanks as always for your educational and broad perspective!