[boost.function] evaluating needed arguments only

Hi,
is it possible to check a function bound to boost::function, if a
particular argument is actually needed?
Example:
----
struct bar {};
typedef boost::function

AMDG Olaf Krzikalla wrote:
is it possible to check a function bound to boost::function, if a particular argument is actually needed?
Boost.Function doesn't provide such a utility. I can't see a way to
get this information out of boost::bind using the public interface, either.
visit_each skips placeholders. If there is a way you would need
something like this
#include

Steven Watanabe wrote:
Boost.Function doesn't provide such a utility. I can't see a way to get this information out of boost::bind using the public interface, either. visit_each skips placeholders. IMHO it should be a feature of boost::function.
If there is a way you would need something like this
#include
#include struct bar {};
class tSlot { public: template<class T> tSlot(const T& t) : uses_placeholder1(false), uses_placeholder2(false), f(t) { // do some magic to find which arguments are used. } But what is the magic here? An approach could be the introduction of a class function_invoker leaving boost::function untouched:
---- struct function_invoker { template<class T> function_invoker(function<T>& f); // throws, if f.empty(); // true, if a placeholder is used by f (should the index i // be zero-based?): bool uses_placeholder(int i) const; // binds arg to a placeholder template<class T> void bind_placeholder(int i, T& arg); template<class T> void bind_placeholder(int i, const T& arg); // throws, if a placeholder used by f is not bound to an argument: fn_result call(); }; ---- I'm aware that the implementation won't be that easy, esp. the static computing of the type of fn_result could become difficult. However it would solve my problem without bloating boost::function: void foo(const tSlot& s) { function_invoker i(s); s.bind_placeholder(1, 1); bar b; if (i.uses_placeholder(2)) // index is one-based) { expensive_calculation(b); s.bind_placeholder(2, b); } s.call(); } I'm wondering if Douglas Gregor is lurking and what his opinion is. Best regards Olaf Krzikalla

AMDG Olaf Krzikalla wrote:
Steven Watanabe wrote:
Boost.Function doesn't provide such a utility. I can't see a way to get this information out of boost::bind using the public interface, either. visit_each skips placeholders.
IMHO it should be a feature of boost::function.
I strongly disagree. a) It requires Boost.Function to treat function object created by Boost.Bind specially. b) Most people don't need it and it will add overhead even when it isn't used.
uses_placeholder2(false), f(t) { // do some magic to find which arguments are used. }
But what is the magic here?
It would have to peek at the Boost.Bind internals, I think.
I'm aware that the implementation won't be that easy, esp. the static computing of the type of fn_result could become difficult.
You would need to specify fn_result as a top level template parameter. Also, there are serious problems with the multiple dispatching required to do the binding. In Christ, Steven Watanabe
participants (2)
-
Olaf Krzikalla
-
Steven Watanabe