boost::bind and member template functions
I can't seem to make boost::bind work with a member template function and it seems like is should. The following won't compile with MSVC 7.0, struct Test_t { template<typename T> void testV( int i, std::vector<T>& b ) { b.push_back( static_cast<T>(i) ); } char m_c; }; void MyTest() { int i(1); Test_t t; std::vector<long> v; boost::bind( &Test_t::testV<long>, t, _1, v )(i); } I get a whole bunch of wrong number of arguments errors. I tried the boost::bind<void> variation and that also won't compile, just with a little different error of the form "cannot convert parameter 1 from 'void (int,std::vector<_Ty> &)' to 'boost::type<T>'" If testV is just a regular template function, not a member of a class or struct, it works fine. Anybody have any idea how to make this work? Thanks, Matt S.
Matt Schuckmann
I can't seem to make boost::bind work with a member template function and it seems like is should.
The following won't compile with MSVC 7.0,
Hi, It's a bug in MSVC. You can try this workaround: void ( Test_t::*f )( int, std::vector<long> & ) = &Test_t::testV<long>; boost::bind( f, t, _1, v )(i); Another options is to deduce type automatically: struct Appender { typedef void result_type; template <class T> void operator()( Test_t & t, int i, std::vector<T>& b ) const { t.testV( i, b ); } }; boost::bind( Appender(), t, _1, v )(i); Roman Perepelitsa.
Thanks Matt S. Roman Perepelitsa wrote:
Matt Schuckmann
writes: I can't seem to make boost::bind work with a member template function and it seems like is should.
The following won't compile with MSVC 7.0,
Hi,
It's a bug in MSVC. You can try this workaround:
void ( Test_t::*f )( int, std::vector<long> & ) = &Test_t::testV<long>; boost::bind( f, t, _1, v )(i);
Another options is to deduce type automatically:
struct Appender { typedef void result_type; template <class T> void operator()( Test_t & t, int i, std::vector<T>& b ) const { t.testV( i, b ); } };
boost::bind( Appender(), t, _1, v )(i);
Roman Perepelitsa.
participants (2)
-
Matt Schuckmann
-
Roman Perepelitsa