Re: Handle class conversion. Open discussion.

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Handle-class-conversion-Open-discussion-tp8938p8940.html

On Tue, 2011-01-04 at 10:36 +0000, Simon Ibbotson wrote:
> I created some dynamic_handle_cast code about 2 years ago. There was
> some discussion at the time: see 28th Feb 2008
>
> http://osdir.com/ml/finance.quantlib.devel/2008-02/
>
> I submitted an implementation but had no response - and it hasn't made
> its way into the library. I can provide it again if required.

Hi Simon,
        sorry for the contribution being lost silently---I guess I lost track
of it.  I went back to it, and it seems to me it adds quite a bit of
complexity to the Handle class.  We can discuss it, though (for
instance, would it be acceptable for your use cases to have a separate
class for that?)

However, unless I misinterpreted Kakhkhor's post, his proposal was to
enable upcasting from Handle<Derived> to Handle<Base>, while yours
implemented downcasting from Handle<Base> to Handle<Derived>.  I think
upcasting was not implemented originally because all handles were
relinkable, and that made upcasting risky (as in:

class A {};
class B : public A {};
class C : public A {};

Handle<B> h1;
Handle<A> h2 = h1;
h2.linkTo(shared_ptr<C>(...));
// ... and now you're in trouble, because your
// original Handle<B> links to a C which is not a B.

for the same reason, C++ doesn't allow casting from Derived** to Base**)

But now that you can't link through a Handle, it might be safe (provided
that when you upcast a RelinkableHandle you get a simple Handle.)

Luigi


--

Don't say "yes" until I finish talking.
-- Darryl F. Zanuck



------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev