boost::bind does not trigger template instantiation

HI, in my spirit grammar file, I use boost::bind to bind a template function: boos::bind(&std::vector<uint32_t>::push_back)(my_vector, i); This compiles fine. However, since this is the only usage of std::vector<uint32_t>::push_back, this function is not instantiated and linker complains that this function is not defined. I could write a wrapper function around std::vector<uint32_t> to force its instantiation. My questions is: is there a more elegant solution in this scenario? Yingwei Zhang Powerset

On 25/02/2008, Yingwei Zhang <ywz@powerset.com> wrote:
HI, in my spirit grammar file, I use boost::bind to bind a template function: boos::bind(&std::vector<uint32_t>::push_back)(my_vector, i);
This compiles fine. However, since this is the only usage of std::vector<uint32_t>::push_back, this function is not instantiated and linker complains that this function is not defined.
I could write a wrapper function around std::vector<uint32_t> to force its instantiation. My questions is: is there a more elegant solution in this scenario?
Yingwei Zhang Powerset
Have a look at the predefined push_back actions in http://boost.org/libs/spirit/doc/predefined_actors.html. They are effectively pre-written wrapper functions, so save you the effort of writing them. Stuart Dootson

Yingwei Zhang:
HI, in my spirit grammar file, I use boost::bind to bind a template function: boos::bind(&std::vector<uint32_t>::push_back)(my_vector, i);
This compiles fine. However, since this is the only usage of std::vector<uint32_t>::push_back, this function is not instantiated and linker complains that this function is not defined.
This is an unfortunate compiler bug. You can force the instantiation of the function by using typedef std::vector<uint32_t> V; void (V::*pm)( uint32_t const& ) = &V::push_back; boost::bind( pm, ... ); but it's somewhat clumsy. I know of no other fix apart from upgrading your compiler.
participants (3)
-
Peter Dimov
-
Stuart Dootson
-
Yingwei Zhang