[proto][can_be_called]

Currently, can_be_called<> expects only functors. Is it possible to extend it so that it can take any type and return true if that type can be called with the list of given parameters. For example, function<int (int, char, long)> functor; int f(int, char, long); int dummyInt; int main(int argc, char ** argv) { assert(false == test(functor, argc, 11, argv)); assert(true == test(functor, 10, 11, 12)); assert(true == test(f, 10, 11, 12)); assert(false == test(dummyInt, 1)); } Thanks, Andy.

Andy Venikov wrote:
Currently, can_be_called<> expects only functors.
Is it possible to extend it so that it can take any type and return true if that type can be called with the list of given parameters.
For example,
function<int (int, char, long)> functor; int f(int, char, long); int dummyInt;
int main(int argc, char ** argv) { assert(false == test(functor, argc, 11, argv)); assert(true == test(functor, 10, 11, 12));
assert(true == test(f, 10, 11, 12)); assert(false == test(dummyInt, 1)); }
<snip> Sorry, forgot the implementation of function template test: template <typename Func, typename ... Prms> inline bool test(Func && func, Prms && ... prms) { return can_be_called<Func, Prms...>::value; }

On 05/06/10 12:47, Andy Venikov wrote: [snip]
Sorry, forgot the implementation of function template test:
template <typename Func, typename ... Prms> inline bool test(Func && func, Prms && ... prms) { return can_be_called<Func, Prms...>::value; }
Andy, I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also: http://www.boost.org/doc/libs/1_42_0/doc/html/proto/reference.html#proto.ref... doesn't have it. Where is this can_be_called template? -regards, Larry

Larry Evans wrote:
On 05/06/10 12:47, Andy Venikov wrote: [snip]
Sorry, forgot the implementation of function template test:
template <typename Func, typename ... Prms> inline bool test(Func && func, Prms && ... prms) { return can_be_called<Func, Prms...>::value; }
Andy,
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also:
http://www.boost.org/doc/libs/1_42_0/doc/html/proto/reference.html#proto.ref...
doesn't have it.
Where is this can_be_called template?
-regards, Larry
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I'm not sure exactly where in the source it is, but here's the doc by Eric Niebler: http://www.boost.org/doc/libs/1_41_0/doc/html/proto/appendices.html#boost_pr... I'm not using it so far, that's why I don't know if it really exists. I was trying to evaluate if I can use it, that's why I asked the question. If you didn't find it in the source, maybe it's not there... Andy.

Larry Evans <cppljevans <at> suddenlink.net> writes:
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also:
http://www.boost.org/doc/libs/1_42_0/doc/html/proto/reference.html#proto.ref... ce.classes I believe that the docs are just using it as an example rather than adding it to the library. See the following thread where Rutger gives a good implementation using this approach (certainly better than my version). http://old.nabble.com/-traits-function_types-generic--Can-F-be-called-with- %7Ba0,-...,-aN%7D--td27760559.html Also see the comments on the limitations: This approach and code does not seem to work with function objects from: boost::lambda, boost::lambda::bind, boost::phoenix, and my implementation of std::lambda under MSVC. If anyone can figure out a consistent way for 'can_be_called' work for all of these different objects, it would be a great addition. And for Phoenix3, maybe support could be added for this type of operation? I had previously asked about this http://groups.google.com/group/boost- list/browse_thread/thread/8e54612df8c92671/b4b9dcaa91f61094?lnk=raot but ultimately failed to figure it out.

On 5/6/2010 2:43 PM, Jesse Perla wrote:
Larry Evans <cppljevans <at> suddenlink.net> writes:
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also: <snip>
See if the code attached to the following ticket meets your needs: https://svn.boost.org/trac/boost/ticket/3783 -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler schrieb:
On 5/6/2010 2:43 PM, Jesse Perla wrote:
Larry Evans <cppljevans <at> suddenlink.net> writes:
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also:
<snip> See if the code attached to the following ticket meets your needs: https://svn.boost.org/trac/boost/ticket/3783
I ran into the same problem some months ago and did also my own implementation. However the implementation by eric_niebler seems to be more generic and it works IMHO also for boost::function and boost::phoenix. (Verified by some simple test cases) Are test cases and documentation the only things that are needed such that is_callable_with_args can be included in boost? Btw what does calling convention on function types mean here ? -Kim

Kim Kuen Tang wrote:
Eric Niebler schrieb:
On 5/6/2010 2:43 PM, Jesse Perla wrote:
Larry Evans <cppljevans <at> suddenlink.net> writes:
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also:
<snip> See if the code attached to the following ticket meets your needs: https://svn.boost.org/trac/boost/ticket/3783
I ran into the same problem some months ago and did also my own implementation. However the implementation by eric_niebler seems to be more generic and it works IMHO also for boost::function and boost::phoenix. (Verified by some simple test cases)
Are test cases and documentation the only things that are needed such that is_callable_with_args can be included in boost? Btw what does calling convention on function types mean here ?
-Kim _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I would definitely vote for this functionality to be included into Boost. This is a third time in the past 6 month that I needed it. I also wanted to return to another request of mine that I raised a couple of months ago, namely for boost::bind to use can_be_called to SFINAE away operator()'s that are not callable. Currently, bind's operator() is just a plain template. It means that it breaks the the type uniformity. For example, if an underlying functor can't be called with given arguments, bind's operator() would still get instantiated and then you'll get a compile-time error not during SFINAE, but inside operator(), which is too late. Thanks, Andy.

On 5/7/2010 2:02 AM, Kim Kuen Tang wrote:
Eric Niebler schrieb:
See if the code attached to the following ticket meets your needs: https://svn.boost.org/trac/boost/ticket/3783
I ran into the same problem some months ago and did also my own implementation. However the implementation by eric_niebler seems to be more generic and it works IMHO also for boost::function and boost::phoenix. (Verified by some simple test cases)
Good to know.
Are test cases and documentation the only things that are needed such that is_callable_with_args can be included in boost?
Test cases are attached to the ticket. Documentation is not. What is really needed is someone to light a fire under Tobias Schwinger. He's the maintainer of the function types library. Tobias?
Btw what does calling convention on function types mean here ?
It means that on some compilers, void (__stdcall *)() is a different type than void (__cdecl *)(). This utility should accommodate all calling conventions. -- Eric Niebler BoostPro Computing http://www.boostpro.com

On 05/07/10 01:44, Eric Niebler wrote:
On 5/6/2010 2:43 PM, Jesse Perla wrote:
Larry Evans <cppljevans <at> suddenlink.net> writes:
I just did svn update for trunk, and then grep'ed for can_be_called; however, nothing turned up. Also: <snip>
See if the code attached to the following ticket meets your needs: https://svn.boost.org/trac/boost/ticket/3783
FWIW, a method not using the boost preprocessor but probably less generic than that is attached. The initial problem I encountered was how to generate: static A &a; static B &b; for each argument. This would be a good use case for "Member Declaration Packs" as proposed here: http://groups.google.com/group/comp.std.c++/msg/f4a61f249fd77c97 However, since that's not available, the: at_type_value<Indices,Args>::value()... expansion seems a good substitute.

On 05/08/10 13:26, Larry Evans wrote: [snip]
FWIW, a method not using the boost preprocessor but probably less generic than that is attached. [snip] I forgot to mention that it uses the variadic mpl template library here:
participants (5)
-
Andy Venikov
-
Eric Niebler
-
Jesse Perla
-
Kim Kuen Tang
-
Larry Evans