[FunctionTypes] Testing for a general callable type.

Hi All Is there anything in Boost to help me test for a general type being callable with a specific signature? I've found Boost.FuncionTypes, which seems to be confined to *builtin* callable types, but has made me aware that all the const/volatile/reference variations might make a general test more complicated than I first thought. Any pointers much appreciated. Thx, Rob.

2013/3/22 Robert Jones
Hi All
Is there anything in Boost to help me test for a general type being callable with a specific signature? I've found Boost.FuncionTypes, which seems to be confined to *builtin* callable types, but has made me aware that all the const/volatile/reference variations might make a general test more complicated than I first thought.
Any pointers much appreciated.
Thx,
Just pushed to github: https://github.com/jamboree/boost.has_call (previous `can_be_called`) HTH

On Fri, Mar 22, 2013 at 1:15 PM, TONGARI
Just pushed to github: https://github.com/jamboree/boost.has_call
(previous `can_be_called`)
Blimey Tongari, that looks like you wrote all that lot in response to my
query, in which case my thanks, just the job! It appears it was as I suspected not entirely straightforward. Rob,

On 22 March 2013 08:15, TONGARI
It doesn't seem to work with default arguments. :-(
Here is my test case (under gcc 4.7.2 -std=c++0x):
#include "boost/type_traits/has_call.hpp"
#include <cassert>
template

On Mon, Mar 25, 2013 at 12:22 PM, Nevin Liber
On 22 March 2013 08:15, TONGARI
wrote: It doesn't seem to work with default arguments. :-(
Here is my test case (under gcc 4.7.2 -std=c++0x):
#include "boost/type_traits/has_call.hpp" #include <cassert>
template
bool HasCall(F const&) { return boost::has_call ::value; } void DefaultVal(int = 0) {}
int main() { assert(HasCall
(DefaultVal)); }
That's because the type of DefaultVal is void ( int ). Function types cannot encode the default'ness of parameters. - Jeff

2013/3/26 Jeffrey Lee Hellrung, Jr.
On Mon, Mar 25, 2013 at 12:22 PM, Nevin Liber
wrote: On 22 March 2013 08:15, TONGARI
wrote: It doesn't seem to work with default arguments. :-(
Here is my test case (under gcc 4.7.2 -std=c++0x):
#include "boost/type_traits/has_call.hpp" #include <cassert>
template
bool HasCall(F const&) { return boost::has_call ::value; } void DefaultVal(int = 0) {}
int main() { assert(HasCall
(DefaultVal)); } That's because the type of DefaultVal is void ( int ). Function types cannot encode the default'ness of parameters.
Yes. Instead, the following works:
struct F
{
void operator()(int = 0){}
};
...
assert(HasCall

On 25 March 2013 20:48, Jeffrey Lee Hellrung, Jr. < jeffrey.hellrung@gmail.com> wrote:
That's because the type of DefaultVal is void ( int ). Function types cannot encode the default'ness of parameters.
How about this example? This fails to compile for me, with a template
instantiation ambiguity. Any thoughts?
Thx, Rob.
#include "boost/type_traits/has_call.hpp"
#include <cassert>
template

2013/4/23 Robert Jones
On 25 March 2013 20:48, Jeffrey Lee Hellrung, Jr. < jeffrey.hellrung@gmail.com> wrote:
That's because the type of DefaultVal is void ( int ). Function types cannot encode the default'ness of parameters.
How about this example? This fails to compile for me, with a template instantiation ambiguity. Any thoughts?
Thx, Rob.
#include "boost/type_traits/has_call.hpp" #include <cassert>
template
bool HasCall(F const&) { return boost::has_call ::value; } void DefaultVal(int) {}
int main() { assert(HasCallboost::dont_care(int)(DefaultVal)); }
Sorry, it was a bug in C++11 mode. It's fixed on my github now, please check. https://github.com/jamboree/boost.has_call Seems that I missed the testcase for 'dont_care', will add later...

On 13-03-22 06:15 AM, TONGARI wrote:
On 2013/3/22, Robert Jones wrote:
Hi All
Is there anything in Boost to help me test for a general type being callable with a specific signature? I've found Boost.FuncionTypes, which seems to be confined to *builtin* callable types, but has made me aware that all the const/volatile/reference variations might make a general test more complicated than I first thought.
Any pointers much appreciated.
Thx,
Just pushed to github: https://github.com/jamboree/boost.has_call
(previous `can_be_called`)
This appears to owe a debt to: http://www.boost.org/doc/libs/1_53_0/doc/html/proto/appendices.html#boost_pr... ... so you should have an attribution somewhere. Apologies if I missed it. -- Eric Niebler Boost.org

On 13-03-22 06:15 AM, TONGARI wrote:
Just pushed to github: https://github.com/jamboree/boost.has_call
(previous `can_be_called`) This appears to owe a debt to: http://www.boost.org/doc/libs/1_53_0/doc/html/proto/appendices.html#boost_pr...
... so you should have an attribution somewhere. Apologies if I missed it. Agreed. I had written my own implementation of this trait based on the referenced appendix from Boost.Proto's documentation, but the one
On 03/26/2013 01:44 AM, Eric Niebler wrote: provided here is more robust than mine. Is it possible that it will be submitted for inclusion into Boost.TypeTraits? It would be nice to have it generally available at some point in the future. Jason

2013/3/26 Jason Roehm
On 03/26/2013 01:44 AM, Eric Niebler wrote:
On 13-03-22 06:15 AM, TONGARI wrote:
Just pushed to github: https://github.com/jamboree/**boost.has_callhttps://github.com/jamboree/boost.has_call
(previous `can_be_called`) This appears to owe a debt to: http://www.boost.org/doc/libs/**1_53_0/doc/html/proto/** appendices.html#boost_proto.**appendices.implementation.**function_arityhttp://www.boost.org/doc/libs/1_53_0/doc/html/proto/appendices.html#boost_pr...
... so you should have an attribution somewhere. Apologies if I missed it.
Agreed. I had written my own implementation of this trait based on the referenced appendix from Boost.Proto's documentation, but the one provided here is more robust than mine. Is it possible that it will be submitted for inclusion into Boost.TypeTraits?
That's what I'd like to see. Maybe I should contact the maintainer of Boost.TypeTraits. ...before that I should write the doc first, alas! It would be nice to have it generally available at some point in the future.
Agreed :)

2013/3/26 Eric Niebler
On 13-03-22 06:15 AM, TONGARI wrote:
On 2013/3/22, Robert Jones wrote:
Hi All
Is there anything in Boost to help me test for a general type being callable with a specific signature? I've found Boost.FuncionTypes, which seems to be confined to *builtin* callable types, but has made me aware that all the const/volatile/reference variations might make a general test more complicated than I first thought.
Any pointers much appreciated.
Thx,
Just pushed to github: https://github.com/jamboree/boost.has_call
(previous `can_be_called`)
This appears to owe a debt to:
http://www.boost.org/doc/libs/1_53_0/doc/html/proto/appendices.html#boost_pr...
... so you should have an attribution somewhere. Apologies if I missed it.
Noted. https://github.com/jamboree/boost.has_call/commit/1c06c41c7d2f88102d61a86904...
participants (6)
-
Eric Niebler
-
Jason Roehm
-
Jeffrey Lee Hellrung, Jr.
-
Nevin Liber
-
Robert Jones
-
TONGARI