Boost logo

Boost Users :

Subject: Re: [Boost-users] [type_traits] deduce argument type of member function with function_traits
From: niXman (i.nixman_at_[hidden])
Date: 2011-09-03 06:38:32


http://liveworkspace.org/code/86e774c3b3de9d7173bb16c00d56eddb

2011/9/3 alfC <alfredo.correa_at_[hidden]>

>
>
> On Saturday, September 3, 2011 1:41:41 AM UTC-7, niXman wrote:
>>
>> May be: http://www.boost.org/doc/**libs/1_47_0/libs/function_**
>> types/doc/html/boost_**functiontypes/reference/**
>> decomposition.html#boost_**functiontypes.reference.**
>> decomposition.parameter_types<http://www.boost.org/doc/libs/1_47_0/libs/function_types/doc/html/boost_functiontypes/reference/decomposition.html#boost_functiontypes.reference.decomposition.parameter_types>
>>
>> ?
>>
>
> good to know! but I still get an error, on this new version.
>
> error: no matching function for call to ‘test(<unresolved overloaded
> function type>)’
> /tmp/tt.cpp:25:6: note: candidate is: void test(F) [with F = char
> (csquare_impl::*)(char)const]
>
> but "run" is not overloaded !, and I don't know how to cast to resolve the
> overload.
>
>
> #include <typeinfo>
> #include <iostream>
> #include <boost/type_traits/function_traits.hpp>
> #include <boost/type_traits/remove_pointer.hpp>
> #include <boost/function_types/parameter_types.hpp>
> #include <boost/mpl/vector.hpp>
> #include <boost/mpl/int.hpp>
> #include <boost/mpl/at.hpp>
>
>
> using namespace std;
>
> double dsquare(double l){ return l*l; }
> int isquare(int l){ return l*l; }
>
> struct csquare_impl{
> char run(char c) const{return 'c';}
>
> };
> csquare_impl csquare;
>
> template<class F>
> void test(F f){
> // works
> // typename boost::function_traits<typename
> boost::remove_pointer<F>::type>::arg1_type test_var;
> // works too, more elegant(?)
> typename boost::mpl::at_c<typename
> boost::function_types::parameter_types<F>::type, 0 >::type test_var;
>
> cout << typeid(test_var).name() << endl;
> }
>
> int main(){
> test(dsquare); // ok, prints "d"(double)
> test(isquare); // ok, prints "i"(int)
> test(csquare.csquare_impl::run); // not ok, want to print "c"(char)
> return 0;
> }
>
>
> BTW, this type traits is a mess, everything it is all over the place,
> Boost.FunctionTypes, Boost.TypeTraits.FunctionTraits, Boost.Functional.
>
>
>>
>> 2011/9/3 alfC <alfredo..._at_[hidden]>
>>
>>> Is function_traits the right way to extract the argument type of a member
>>> function?
>>>
>>> In the following example I want to make the last line work. This will be
>>> part of larger question, on how to deduce the argument type of operator()
>>> for function objects in which operator() is not overloaded.
>>>
>>> #include <typeinfo>
>>> #include <iostream>
>>> #include <boost/type_traits/function_**traits.hpp>
>>> #include <boost/type_traits/remove_**pointer.hpp>
>>>
>>> using namespace std;
>>>
>>> double dsquare(double l){ return l*l; }
>>> int isquare(int l){ return l*l; }
>>>
>>> struct csquare_impl{
>>> int do(char c) const{
>>> return 'c';
>>> }
>>> };
>>> csquare_impl csquare;
>>>
>>> template<class F>
>>> void test(F f){
>>> typename boost::function_traits<**typename
>>> boost::remove_pointer<F>::**type>::arg1_type test_var;
>>> cout << typeid(test_var).name() << endl;
>>> }
>>>
>>> int main(){
>>> test(dsquare); // ok, prints "d"(double)
>>> test(isquare); // ok, prints "i"(int)
>>> test(csquare_impl::do); // not ok, want to print "c"(char)
>>> return 0;
>>> }
>>>
>>> Thanks,
>>> Alfredo
>>>
>>> ______________________________**_________________
>>> Boost-users mailing list
>>> Boost..._at_[hidden]
>>>
>>> http://lists.boost.org/**mailman/listinfo.cgi/boost-**users>
>>>
>>
>>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
>
http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net