Subject: [boost] [function] "paranoia" vs efficiency
From: Domagoj Saric (domagoj.saric_at_[hidden])
Date: 2009-10-02 07:20:23
As far as I can see boost::function<>::operator() performs:
before invoking the stored function (object)...
My question is why or why only this "checked"/"safe" approach/method of
- causes (extra) code branching
- causes the compiler to insert exception throwing and handling code in
surrounding/calling code (which need not otherwise be if the function stored
in the boost function instance is itself nothrow)
- inserts a call to the bad_function_call constructor
- disables the compiler from inlining the function (MSVC atleast)
- disables NVRO (MSVC atleast,
while at the same time I would most often consider calling a
"null-function-pointer" a programmer error (that would therefor need to be
"handled" with an assert not an exception), not a runtime 'unpredictable'
...IMO the default should be not to include this check (i.e. use an assert)
and provide a safeInvoke() type of method for those users and cases that
actually require/want this type of check/behaviour...
...or atleast "it would be welcomed" if a non-checking unsafeInvoke() type
of method would be provided for those that are 'sure' that the
boost::function<> object is valid (for example in the line before i've just
performed the same check to decide whether to call the function object or
-- "That men do not learn very much from the lessons of history is the most important of all the lessons of history." Aldous Huxley