From -6909900332717809355
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fb1a92fa405c930c
X-Google-Attributes: gidf78e5,public
From: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Subject: Re: nested functions
Date: 1999/06/06
Message-ID: <375A17D3.482@wanadoo.fr>#1/1
X-Deja-AN: 486239817
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <7jd4c5$nup$1@nnrp1.deja.com>
X-Original-Date: Sun, 06 Jun 1999 08:40:19 +0200
Content-Type: text/plain; charset=us-ascii
Organization: Ecole normale superieure
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUAN1od3qwEuYhIxRhxAQHtegH8DFjFB5fBF/h/qHw4nYaTXCGRzVwtET3F 6aafVOhdCu/JajOh9XnYyKkAqFuawPRO7vxtvdhwwSQ9E0jdANeYnw== =iq+D
Mime-Version: 1.0
Newsgroups: comp.std.c++

gbush@my-deja.com wrote:

> C++ unlike other languages doesn't support nested functions. I
> understand, bad heredity. But C++ had an opportunity to escape from
> this predicament by allowing classes inside function body see the local
> non-static variables, defined in the outer scope as well as function
> parameters. For some reason it was not done. I wonder, is there at
> least one good reason why it is so? (You see, I don't ask about five
> good reasons anymore, just one.) I understand, certainly, that someone
> could return object that contains references to local variables, but it
> hardly can be considered a good reason.

This has already been discussed here.

Andrew Koenig said (approximatly) that it was a big 
philosophical change to allow local classes to 
access locals.

James and I propose to introduce a new class, 
__local_context, defined in every function 
scope, which represents the locals in the scope.

Then all you would need to do is to derive your 
local class from this class:

void foo ()
{
    int i;

    struct loc : __local_context {
        int operator() () { return i; }
        loc (__local_context c) : __local_context (c) {}
    };
    cout << loc (__local_context());
}

...well, you get the idea; if you add a lambda 
construct for creating local clases easilly, and 
give local classes external linkage, then you 
get a functionnal language.

-- 

Valentin Bonnard
---
[ 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              ]



