Topic: void return statements
Author: "Joerg Schaible" <Joerg.Schaible@no-spam.gft.de>
Date: 1999/03/16 Raw View
>When I ran into this problem, I chose the latter approach. I was working
>with my own adapters, and made copies of the class and function called the
>equivalent of mem_fun_void_t and mem_fun_void. You can do the same,
>starting with the implementations in your STL implementation. It shouldn't
>take more than about a dozen lines of code.
Did the same ... and had to repeat it for const member functions ...
J rg
--
BTW: It is normally better to answer to the group! For direct mail reply
remove "no_spam."
[ 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 ]
Author: Philip Brabbin <pabrabbin@yahoo.com>
Date: 1999/03/12 Raw View
I was recently trying to use the standard library function mem_fun() in
conjunction with a member function which returned no value (ie. 'void'
return type). My compiler refused to let this compile on the grounds
that my implementation of mem_fun() (which is a template function) was
attempting to return the value of the member function call - in this
case 'void'.
Stroustrup's 3rd edition says that this construction is actually legal,
but my compiler (MS VC++ 6) and the online Draft Standard at Warwick
seem to suggest otherwise.
Does anybody know if this new use of 'return' found its way into the
ANSI Standard, or was there an oversight in the design of mem_fun() ?
Thanks,
Phil Brabbin
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com
---
[ 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 ]
Author: "Ed Brey" <brey@afd.mke.etn.com>
Date: 1999/03/12 Raw View
C++ allows a "return void;" so that functions like mem_fun work with no
return type. True to form, MS VC++ doesn't support return void.
SGI has a blurb about non-support for return void in their STL
implementation file stl_function.h. SGI implements a work-around for
compilers that don't return void by partially specializing mem_fun where
_Ret is void. True to form, MS VC++ doesn't support partial specialization
either; otherwise, you could have used their STL to solve the problem or
reimplemented their work-around yourself.
Microsoft's STL implementation doesn't include the specialization
workaround, since workaround that doesn't work doesn't have a point to
being around.
Your stuck with making your adapted function return a bogus value, or
writing your own versions of mem_fun_t and mem_fun with their own names to
work around the problem.
When I ran into this problem, I chose the latter approach. I was working
with my own adapters, and made copies of the class and function called the
equivalent of mem_fun_void_t and mem_fun_void. You can do the same,
starting with the implementations in your STL implementation. It shouldn't
take more than about a dozen lines of code.
[ 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 ]
Author: Stephen.Clamage@sun.com (Steve Clamage)
Date: 1999/03/12 Raw View
Philip Brabbin <pabrabbin@yahoo.com> writes:
>I was recently trying to use the standard library function mem_fun() in
>conjunction with a member function which returned no value (ie. 'void'
>return type). My compiler refused to let this compile on the grounds
>that my implementation of mem_fun() (which is a template function) was
>attempting to return the value of the member function call - in this
>case 'void'.
>Stroustrup's 3rd edition says that this construction is actually legal,
>but my compiler (MS VC++ 6) and the online Draft Standard at Warwick
>seem to suggest otherwise.
Section 6.6.3 in the standard contains this paragraph:
"A return statement with an expression of type "cv void" can be used
only in functions with a return type of cv void; the expression is
evaluated just before the function returns to its caller."
(The "cv" means optional const and/or volatile qualifiers.)
It's a fairly recent addition to the standard, and some compilers
might not support it yet. The change was made to support precisely
the code you are writing. Without the rule, you need a specialization,
or partial specialization, of the template for type void.
--
Steve Clamage, stephen.clamage@sun.com
[ 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 ]
Author: "Paul Grealish" <paul.grealish@uk.geopak-tms.com>
Date: 1999/03/13 Raw View
Philip Brabbin wrote in message
<19990311185918.18718.rocketmail@send205.yahoomail.com>...
>I was recently trying to use the standard library function mem_fun() in
>conjunction with a member function which returned no value (ie. 'void'
>return type). My compiler refused to let this compile on the grounds
>that my implementation of mem_fun() (which is a template function) was
>attempting to return the value of the member function call - in this
>case 'void'.
>
>Stroustrup's 3rd edition says that this construction is actually legal,
>but my compiler (MS VC++ 6) and the online Draft Standard at Warwick
>seem to suggest otherwise.
>
>Does anybody know if this new use of 'return' found its way into the
>ANSI Standard, or was there an oversight in the design of mem_fun() ?
This question's come up before
(quick fumble around in dejanews...)
Francis Glassborow wrote:
>
> In article <362F5757.2D85@bogus.acm.org>, Thant Tessman
> <thant@bogus.acm.org> writes
> >Should this be legal?
> >
> >
> > void foo() {}
> >
> > void bar() {return foo();}
> >
> > int main() {
> >
> > bar();
> > }
> >
> >
> >If so, can someone point me at the relavent section of the standard?
>
> Yes it is legal (someone else will have to provide the relevant quote)
> an explicit decision was made very late in the standards process
> (precisely because it would be useful in templates) to allow code such
> as that in the return from bar. However many compilers may not have
> caught up with it. I just did a quick test on CodeWarrior 4 and it
> happily compiles and executes your code.
>
> Francis Glassborow Chair of Association of C & C++ Users
> 64 Southfield Rd
> Oxford OX4 1PA +44(0)1865 246490
> All opinions are mine and do not represent those of any organisation
+---------------------------------+
| Paul Grealish |
| GEOPAK-TMS Limited |
| Cambridge, England |
| paul.grealish@uk.geopak-tms.com |
+---------------------------------+
---
[ 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 ]