|
Boost Users : |
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2004-12-27 09:08:00
Dear all,
Yep, again it's me, and it's agian
function_traits<>...
AFAIK, std::iterator_traits<> is one of the
counterparts of function_traits<>, not?
A sort of symmetry which iterator_traits<> has got is
that it can work for Iterators as well as plain
pointers.
This seems to be not the case for function_traits<>.
That is, you can pass a function type to it, but you
can't do that for a functor. Is that right?
If it is, a big drawback turns out to happen for
variations of the following which are not that few
common:
template <
typename ...,
...,
typename Function
>
struct Foo
{
typedef
typename
function_traits<Function>
::result_type result_type;
Foo (Function f) : f_(f) {}
//...
result_type operator () () {/*..*/}
Function f_;
};
This well works for sth like this:
double f(double) {/*...*/}
Foo<blah, ..., double (&) (double)> foo(f);
But it does not work with the following:
struct F
{
double operator () () {/*...*/}
};
Foo f;
Foo<blah, ..., F> foo(f);
Is this what it should be? Or am I missing anything?
In fact, the following code:
struct F
{
double operator () (double x) const {return f(x);}
};
typedef
boost::function_traits<F>::result_type result_type;
makes GCC 3.3.1 to give me an error like the previous
one. This is what it says:
Compiler: Default compiler
Building Makefile: "C:\Documents and
Settings\Hossein\My Documents\My
Programmes\Probability
I\Distributions\7.2.1\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Hossein\My
Documents\My Programmes\Probability
I\Distributions\7.2.1\Makefile.win" all
g++.exe -D__DEBUG__ -c 7_2_1Main.cpp -o 7_2_1Main.o
-I"C:/Dev-Cpp/include/c++/3.3.1"
-I"C:/Dev-Cpp/include/c++/3.3.1/mingw32"
-I"C:/Dev-Cpp/include/c++/3.3.1/backward"
-I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include"
-I"C:/Dev-Cpp/include" -pg -g3
7_2_1Main.cpp: In instantiation of
`boost::function_traits<F>':
7_2_1Main.cpp:70: instantiated from
`inverse_variate_generator<main()::Engine,
main()::Distribution, F>'
7_2_1Main.cpp:106: instantiated from here
7_2_1Main.cpp:70: error: base class
`boost::detail::function_traits_helper<F*>'
has incomplete type
7_2_1Main.cpp: In instantiation of
`inverse_variate_generator<main()::Engine,
main()::Distribution, F>':
7_2_1Main.cpp:106: instantiated from here
7_2_1Main.cpp:70: error: no type named `result_type'
in `struct
boost::function_traits<F>'
7_2_1Main.cpp:76: error: no type named `result_type'
in `struct
boost::function_traits<F>'
7_2_1Main.cpp: In function `int main()':
7_2_1Main.cpp:113: error: no match for call to `(
inverse_variate_generator<main()::Engine,
main()::Distribution, F>) ()'
7_2_1Main.cpp:117: error: no match for call to `(
inverse_variate_generator<main()::Engine,
main()::Distribution, F>) ()'
make.exe: *** [7_2_1Main.o] Error 1
Execution terminated
What's wrong with it? Am I missing anything?
If I'm not missing anything, then what is the
work-around? I find myself right in expecting myself
to be able to write a functor (like Foo) which can
work equaly well with both function pointers and
functors, as like as how the Standard algorithms do.
Am I right? Or am I right? ;)
TIA,
--Hossein
__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo
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