[Container] ptr_set with user define compare function

I've defined a function object as below: struct BaseAddrLess : public std::binary_function<Base, Base, bool> { result_type operator() (const first_argument_type& lhs, const second_argument_type& rhs) const { return &lhs < &rhs; } }; and use as a compare function in ptr_set like this: ptr_set<Base, BaseAddrLess> bset; when the class Base is a abstract class the vc9 compiler will complain use of undefined type 'boost::result_of<F>' What causes this problem? How to solve it? Thank you for your patience to read my poor english. S.C. Leung

AMDG 梁绍池 wrote:
I've defined a function object as below:
struct BaseAddrLess : public std::binary_function<Base, Base, bool> { result_type operator() (const first_argument_type& lhs, const second_argument_type& rhs) const { return &lhs < &rhs; } };
and use as a compare function in ptr_set like this: ptr_set<Base, BaseAddrLess> bset;
when the class Base is a abstract class the vc9 compiler will complain use of undefined type 'boost::result_of<F>'
What causes this problem? How to solve it?
Works for me. Do you have a minimal test case that fails? What version of Boost are you using? #include <functional> #include <boost/ptr_container/ptr_set.hpp> struct Base { virtual ~Base() = 0; }; Base::~Base() {} struct Derived : Base {}; struct BaseAddrLess : public std::binary_function<Base, Base, bool> { result_type operator() ( const first_argument_type& lhs, const second_argument_type& rhs) const { return &lhs < &rhs; } }; int main() { boost::ptr_set<Base, BaseAddrLess> bset; bset.insert(new Derived()); } In Christ, Steven Watanabe

Hello, Steven Your test case is failed in my environment. I use boost 1.36.0 then I replaced my boost with 1.39.0 and found it works! What's the difference between them? 2009/5/23 Steven Watanabe <watanabesj@gmail.com>
AMDG
梁绍池 wrote:
I've defined a function object as below:
struct BaseAddrLess : public std::binary_function<Base, Base, bool> { result_type operator() (const first_argument_type& lhs, const second_argument_type& rhs) const { return &lhs < &rhs; } };
and use as a compare function in ptr_set like this: ptr_set<Base, BaseAddrLess> bset;
when the class Base is a abstract class the vc9 compiler will complain use of undefined type 'boost::result_of<F>'
What causes this problem? How to solve it?
Works for me. Do you have a minimal test case that fails? What version of Boost are you using?
#include <functional> #include <boost/ptr_container/ptr_set.hpp>
struct Base { virtual ~Base() = 0; };
Base::~Base() {}
struct Derived : Base {};
struct BaseAddrLess : public std::binary_function<Base, Base, bool> { result_type operator() ( const first_argument_type& lhs, const second_argument_type& rhs) const { return &lhs < &rhs; } };
int main() { boost::ptr_set<Base, BaseAddrLess> bset; bset.insert(new Derived()); }
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

梁绍池 skrev:
Hello, Steven
Your test case is failed in my environment. I use boost 1.36.0
then I replaced my boost with 1.39.0 and found it works!
What's the difference between them?
This was a bug up to 1.38. The problem was that the expression used in result_of<> passed the arguments by value which fails with abstract base classes. -Thorsten
participants (3)
-
Steven Watanabe
-
Thorsten Ottosen
-
梁绍池