From 2069416316144702104
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,18c6d861cef54158
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-01-03 08:43:33 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: brangdon@cix.co.uk (Dave Harris)
Newsgroups: comp.std.c++
Subject: Re: automatic downcast support through function parameters
Date: Fri, 3 Jan 2003 16:43:30 +0000 (UTC)
Lines: 74
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <memo.20030103104316.13945B@brangdon.madasafish.com>
References: <23478c42.0212310830.23dbc580@posting.google.com>
X-Trace: mail2news.demon.co.uk 1041612210 25864 10.0.0.1 (3 Jan 2003 16:43:30 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 3 Jan 2003 16:43:30 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18UUuu-0006j1-00
	for mail2news@news.news.demon.net; Fri, 03 Jan 2003 16:43:29 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id DAA10682; Sat, 4 Jan 2003 03:42:51 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-Reply-To: brangdon@cix.co.uk
X-Orig-NNTP-Posting-Host: pc1-clif1-6-cust113.nott.cable.ntl.com (80.4.200.113)
X-Orig-X-Trace: fu-berlin.de 1041590489 11926590 80.4.200.113 (16 [57443])
X-MailScanner: PASSED (v1.2.7 93133 h03AfTf9002057 mailbox5.ucsd.edu)
X-Spam-Status: No, hits=-6.1 required=5.0
	tests=QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_03_05
	version=2.41
Xref: archiver1.google.com comp.std.c++:16681

danielgutson@hotmail.com (danielgutson@hotmail.com) wrote (abridged):
>  - The idea here is that f ignores the function that will be finally
>  invoked, but knows that the pointer was upcasted ('upcasted'
> keyword).
>  Then, the function accepting the most derived class (closest to the
>  original type) will be invoked, in this case: g(Der*).
> 
> The 'spirit' of this is to recover specificity: in the process flow:
>   main -> f -> g
> specificity(main) = specificity(g) > specificity(f)
> and this would be an automatic way of recoviring specificity at g,
> without loosing generality at f.

To me this looks like a form of multi-method. As traditionally formulated, 
multi-methods change the syntax for the callee, rather than the caller as 
you have it. Your example would be written:
  
  struct Base{};
  struct Der : Base{};
 
  void g(virtual Base* b);
  void g(virtual Der* d);
 
  void f(Base* b)
  {
    g(b); // May invoke the Der-specific version.
  }

See Stroustrup's "Design and Evolution of C++" $13.8 for more details. 


>  What you think?

The basic aim - to recover specificity - is good. Stroustrup wanted it 
too, and says he regretted not being able to include multi-methods in C++. 
He describes the issues in D&E. It's welcome to see a fresh approach.

One problem with changing the caller is that you might have several calls 
in scope and not want them all to use the dynamic dispatch. Eg:

    void f2( upcasted Base *b ) {
        g(b); // Want dynamic dispatch here.
        h(b); // Don't want it here.
    }

We might want to turn it off because, when multiple arguments are 
involved, the call may be ambiguous at run-time. (And there may be 
performance reasons, too.)

Another problem is that calls to the same function may be resolved 
dynamically in some places and statically in others, by accident, if 
someone forgets to say "upcasted" at the point of call.

Other issues, common to ordinary multi-methods, are (a) how to handle 
ambiguous cases with multiple arguments (can errors be detected at 
compile-time?); and (b) how to implement it efficiently. 

And there are some details which are not clear. Are you supposing that the 
only candidate functions are the ones in scope at the point of call? This 
would make the mechanism less flexible. In effect, f() needs to know about 
every derived class of Base, which kinda goes against object oriented 
principles.

  Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
      brangdon@cix.co.uk      |   And close your eyes with holy dread,
                              |  For he on honey dew hath fed
 http://www.bhresearch.co.uk/ |   And drunk the milk of Paradise."

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



