From 8064052134216057782
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: James.Kanze@dresdner-bank.com
Subject: Re: nested functions
Date: 1999/06/16
Message-ID: <7k5ssr$pll$1@nnrp1.deja.com>#1/1
X-Deja-AN: 490110764
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <7jd4c5$nup$1@nnrp1.deja.com> <7jfkcr$na6$1@engnews1.eng.sun.com> <7jjq0g$tlu$1@nnrp1.deja.com> <slrn7lrin4.ajs.sbnaran@localhost.localdomain>
X-Original-Date: Tue, 15 Jun 1999 15:53:06 GMT
X-Http-User-Agent: Mozilla/4.6 [en] (WinNT; I)
X-Complaints-To: news@news.unimelb.edu.au
X-Http-Proxy: 1.0 x43.deja.com:80 (Squid/1.1.22) for client 193.194.7.71
X-Trace: izvestia.its.unimelb.edu.au 929505376 14899 128.250.29.16 (16 Jun 1999 03:56:16 GMT)
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Tue Jun 15 15:53:06 1999 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN2cgReEDnX0m9pzZAQHyVgF/ZsVxyu2UtTovV+kvhn0ZLvAbNHZTVlO9 LeUho6wNHYcE7kfMxyXYntTqq7qztmxX =5JoE
NNTP-Posting-Date: 16 Jun 1999 03:56:16 GMT
Newsgroups: comp.std.c++

In article <slrn7lrin4.ajs.sbnaran@localhost.localdomain>,
  sbnaran@uiuc.edu wrote:
> On 8 Jun 1999 21:26:57 GMT, Andrei Alexandrescu
<andrewalex@hotmail.com> wrote:
>
> >I'd like to have local functions even in the limited way C++'s design
> >allows. Local classes should have linkage so one could use smll
functors
> >with for_each etc. without adding many methods to the class.
>
> Fine, I agree with both your points.
>
> But answer this one question.  Should the local functions and local
> classes be able to access the local context?  J Kanze and V Bonnard
> suggested that we have a pseudo-class 'local_context', and the
> local class can derive from 'local_context' if it wishes to access
> the local context.  But how does the local function access the
> local context?

It's important to note that I have *not* done the work necessary to
present a formal proposal, and that these are mostly just ideas off the
top of my head.  However, my basic idea is that __local_context would be
defined as containing non-const references to all visible local
variables and parameters, with the same name as the variable, and
initialized to refer to the variable.  I'm not sure whether these
members should be protected or public -- I think I rather favor
protected.  And of course, this just defines the semantic; most
compilers will be able to implement the actual accesses directly,
without the intervening reference.

And it goes without saying that any access to an instance of the class
(even one allocated with new) after leaving the function is undefined
behavior.  (Question: should new even be allowed for a class derived
from __local_context?  In many ways, I would prefer not, but I think it
has to: you might want to pass it as a parameter to a function which
takes an auto_ptr.)

> Or perhaps the ability of the local class or local
> function to access the local context should be automatic, without
> any need for the pseudo-class?

Not automatic, IMHO.  It adds overhead to the class.  Most of the time,
you don't want it, and it in fact just represents an additional danger.
(Returning a reference or a pointer to the class effectively invalidates
the class members.  And I often return references or pointers to local
classes.)

--
James Kanze                         mailto:
James.Kanze@dresdner-bank.com
Conseils en informatique orient�e objet/
                        Beratung in objekt orientierter
Datenverarbeitung
Ziegelh�ttenweg 17a, 60598 Frankfurt, Germany  Tel. +49 (069) 63 19 86
27


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



