[function] invoking without requiring boost::throw_exception

Dear all, I am using boost::function on an embedded platform, which requires me to not use exceptions, and as commented in the thread associated with http://article.gmane.org/gmane.comp.lib.boost.devel/195351 I am checking that the function object contains a function before calling it. There is therefore no need for the invocation of the function to check if it is valid, but also there is no method circumvent this checking, and therefore my program requires the definition of boost::throw_exception, when really it is not needed. This is a concern because I intend on compiling my code into a library and do not wish to require the user to define boost::throw_exception, especially when I am guaranteeing it isn't going to be called from this site. I liked the idea of a templated NOP for the function library, but at the very least an unchecked invocation method would be great, or a nop-if-empty invocation method would be useful. A simple addition of the following would assist to some extend : result_type invoke(BOOST_FUNCTION_PARMS) const { return get_vtable()->invoker (this->functor BOOST_FUNCTION_COMMA BOOST_FUNCTION_ARGS); } With maybe a comment next to result_type operator()(BOOST_FUNCTION_PARMS) const; suggesting the use of invoke() when the function is pre-checked, or more importantly you are trying to avoid exception usage. Thanks in advance, and I hope I am not opening a new/old can of worms..... Peter Dr Peter Myerscough-Jackopson - Principal Engineer Tel: +44 (0)23 8076 7808 Fax: +44 (0)23 8076 0602 Web: http://www.macltd.com/ <BLOCKED::http://www.macltd.com/> Email: peter.myerscough-jackopson@macltd.com <mailto:peter.myerscough-jackopson@macltd.com> MULTIPLE ACCESS COMMUNICATIONS LIMITED is a company registered in England at Delta House, The University of Southampton Science Park, Southampton, SO16 7NS, United Kingdom with Company Number 1979185 and VAT Number GB 411942866

From: "Peter Myerscough-Jackopson" <peter.myerscough-jackopson@macltd.com> Sent: Thursday, September 02, 2010 5:36 PM
I am using boost::function on an embedded platform, which requires me to not use exceptions, and as commented in the thread associated with
http://article.gmane.org/gmane.comp.lib.boost.devel/195351
I am checking that the function object contains a function before calling it. There is therefore no need for the invocation of the function to check if it is valid, but also there is no method circumvent this checking, and therefore my program requires the definition of boost::throw_exception, when really it is not needed. This is a concern because I intend on compiling my code into a library and do not wish to require the user to define boost::throw_exception, especially when I am guaranteeing it isn't going to be called from this site. I liked the idea of a templated NOP for the function library, but at the very least an unchecked invocation method would be great, or a nop-if-empty invocation method would be useful.
If you are certain that neither you nor your users use or will use boost::throw_exception (to actually handle some other cases 'exceptional' cases in other parts of boost) then you can provide the definition yourself. Something along the lines of: void throw_exception( std::exception const & ) { assert( !"Should not get reached." ); #ifdef _MSC_VER __assume( false ); #elif defined( __GNUC__ ) __builtin_unreachable(); #else .... #endif } should pretty much completely remove the if-then-throw code from your release binary... ps. the code mentioned in the thread you linked to has since somewhat progressed and can always be found @ https://svn.boost.org/svn/boost/sandbox/function/boost/function ... but it is still in an unfinished-alpha-msvc specific stage ... I haven't touched it in months as there has not been any real response from the official maintainer and I've been swamped with other things (and am currently working on GIL::IO) but will surely finish it when I get the time (now that I've started working with GCC also)... -- "That men do not learn very much from the lessons of history is the most important of all the lessons of history." Aldous Huxley

On Thu, 02 Sep 2010 17:36:26 +0200, Peter Myerscough-Jackopson <peter.myerscough-jackopson@macltd.com> wrote:
[...]I am checking that the function object contains a function before calling it. There is therefore no need for the invocation of the function to check if it is valid, but also there is no method circumvent this checking, and therefore my program requires the definition of boost::throw_exception, when really it is not needed. This is a concern because I intend on compiling my code into a library and do not wish to require the user to define boost::throw_exception, especially when I am guaranteeing it isn't going to be called from this site. I liked the idea of a templated NOP for the function library, but at the very least an unchecked invocation method would be great, or a nop-if-empty invocation method would be useful.
This has recently come up on the Boost.Asio mailing list, too - see <http://thread.gmane.org/gmane.comp.lib.boost.asio.user/4230>. I think everyone wants to see this change. Boris
[...]
participants (3)
-
Boris Schaeling
-
Domagoj Saric
-
Peter Myerscough-Jackopson