Local Functions...

?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

I can't come up with anything that can be accomplished with private
member functions and variables that can't be done with normal global
functions and variables. In fact I find it a bit limiting since such
a private member function or variable can't be called from a scope
outside the class, which means that you can't reuse the function or
variable in some other context.

Yes, I see your point. But data encapsulation is generally accepted as a
Good Thing (TM), and private member functions are a part of that. It is
my understanding that the C++ committee likes to add things that changes
the way people think, and I can't see nested functions doing that.

But who knows, in ten years someone will post some question to a usenet
group and someone will answer "... yes, but it is generally accepted
that nested functions are a Good Thing (TM)...".
 
J

Jerry Coffin

[ ... ]
But who knows, in ten years someone will post some question to a usenet
group and someone will answer "... yes, but it is generally accepted
that nested functions are a Good Thing (TM)...".

I rather doubt it -- nested functions have been around a _long_ time
(e.g. in Pascal) but their lack in C and C++ doesn't seem to have caused
a major problem with usage or popularity. While they are a little bit of
a pain to implement, they're not really all that terrible -- especially
on some processors (such as the x86) that have instructions specifically
tailored to support them. OTOH, support for them is far from universal,
and generally carries some cost even where it's available.

In the end, like most things, it's a question of cost vs. benefit -- the
number of useful local functions is generally fairly small, so the
benefit is usually fairly minimal. The cost isn't terribly high, but
still probably greater than the benefit.
 
J

Juha Nieminen

Jerry said:
I rather doubt it -- nested functions have been around a _long_ time
(e.g. in Pascal) but their lack in C and C++ doesn't seem to have caused
a major problem with usage or popularity. While they are a little bit of
a pain to implement, they're not really all that terrible -- especially
on some processors (such as the x86) that have instructions specifically
tailored to support them. OTOH, support for them is far from universal,
and generally carries some cost even where it's available.

Well, isn't the new C++ standard going to include lambda functions
which, afaik, are like nested function on steroids? So I don't think
it's a question of difficulty of implementation, but simply standardization.
 
J

Jerry Coffin

Well, isn't the new C++ standard going to include lambda functions
which, afaik, are like nested function on steroids? So I don't think
it's a question of difficulty of implementation, but simply standardization.

I'm honestly not sure whether lambda's are included or not. I know
they've been proposed, but the papers I looked at (admittedly, not
within the last few months) didn't look entirely ready for acceptance
into a finished standard yet. Doing a quick search through N2315, the
only uses of "lambda" appear to be related to a random number generator
with an exponential distribution.

If memory serves, however, the proposals I've seen were for implementing
lambdas more or less like Boost does, creating temporary objects rather
than local functions, as such.

I don't have an exact list of the proposals that have been dropped, but
my understanding is that the last committee meeting was the deadline for
new features -- anything that wasn't sufficiently finished that it was
ready to be accepted has been dropped, at least for this round of
standardization. I don't know it for a fact, but my guess would be that
the lambda proposals probably fell into the group that have been dropped
(at least for now).
 
?

=?ISO-8859-15?Q?Erik_Wikstr=F6m?=

I'm honestly not sure whether lambda's are included or not. I know
they've been proposed, but the papers I looked at (admittedly, not
within the last few months) didn't look entirely ready for acceptance
into a finished standard yet. Doing a quick search through N2315, the
only uses of "lambda" appear to be related to a random number generator
with an exponential distribution.

If memory serves, however, the proposals I've seen were for implementing
lambdas more or less like Boost does, creating temporary objects rather
than local functions, as such.

I don't have an exact list of the proposals that have been dropped, but
my understanding is that the last committee meeting was the deadline for
new features -- anything that wasn't sufficiently finished that it was
ready to be accepted has been dropped, at least for this round of
standardization. I don't know it for a fact, but my guess would be that
the lambda proposals probably fell into the group that have been dropped
(at least for now).

Looking at n2336 the Lambda expressions and closures proposal (n2329) is
listed under "Active topics in Evolution" which has the description
"These topics are in final review, with the intention to incorporate
each one in the next standard". The current proposal looks quite
complete to me, but I'm not on the committee, so I hope they will get it in.

I think it would be great to have lambda functions to use with the
standard algorithms such as for_each, find_if, etc.
 
J

Jerry Coffin

[ ... ]
Looking at n2336 the Lambda expressions and closures proposal (n2329) is
listed under "Active topics in Evolution" which has the description
"These topics are in final review, with the intention to incorporate
each one in the next standard". The current proposal looks quite
complete to me, but I'm not on the committee, so I hope they will get it in.

We can hope -- and we should know quite soon. I'm pretty sure it's no
longer a question of whether it _will_ get in, but whether it _has
gotten_ in -- and I believe papers from the last meeting should be
available soon (if they aren't already -- I didn't look today).
I think it would be great to have lambda functions to use with the
standard algorithms such as for_each, find_if, etc.

I certainly like the idea as well, though I find their lack less
bothersome than many.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top