Topic: returning void expressions
Author: jzipnick@best.Please.No.Spam.com (Jay Zipnick)
Date: 1997/11/04 Raw View
Does anyone know the status of the proposal(s) for returning void
expressions (see prior comp.std.c++ message below). I haven't been on
comp.std.c++ recently, so forgive me if this was recently covered.
- Jay
-------------------- prior message --------------------
Paul D. DeRocco <pderocco@ix.netcom.com> writes:
> The C++ standard doesn't allow a return statement with an expression to
> be used in a function whose return type is void.
>
> I suggest that it should be legal to return a void expression from a
> function whose type is void. Why? It can be useful in templates.
> Consider the following:
>
> template <class T, class R> class Functor {
> public:
> R& operator()() { return (obj.*mem)(); }
> Functor(T& o, R& (T::*m)()): obj(o), mem(m) {}
> private:
> T& obj;
> R& (T::*mem)();
> }
>
> This defines a functor containing a pointer to an object to be operated
> on, and a pointer to a member function defined for that object. It
> should work for any member function that takes no arguments and returns
> a result. Unfortunately, it won't work for a member function that
> returns void. If return were modified as described above, this function
> template would work for member functions that return void as well.
I have written a note to the committee formally proposing this. The reason
stated was roughly the one above. In addition - and for the same reason -
I proposed to allow an expression of type void to be used as the argument
of a function taking no argument.
There is no guarantee that the committee will accept this or even that the
committee will consider it (though clearly I think the committee ought
to).
- Bjarne
-------------------------------------------------------
--
(Remove the no spam stuff from my email address to reply)
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: stephen.clamage_nospam@eng.sun.com (Steve Clamage)
Date: 1997/11/05 Raw View
On 04 Nov 97 06:32:37 GMT, jzipnick@best.Please.No.Spam.com (Jay
Zipnick) wrote:
>Does anyone know the status of the proposal(s) for returning void
>expressions (see prior comp.std.c++ message below). I haven't been on
>comp.std.c++ recently, so forgive me if this was recently covered.
>
>- Jay
>
>-------------------- prior message --------------------
>Paul D. DeRocco <pderocco@ix.netcom.com> writes:
>
>> The C++ standard doesn't allow a return statement with an expression to
>> be used in a function whose return type is void.
>>
>> I suggest that it should be legal to return a void expression from a
>> function whose type is void. Why? It can be useful in templates.
The proposal was adopted. It is a pure extension, not changing the
meaning of any current program, but allowing you to write code that
was previously invalid. It is now legal to return an expression of
type void if the return type of the function is also void.
---
Steve Clamage, stephen.clamage_nospam@eng.sun.com
( Note: remove "_nospam" when replying )
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]