Boost logo

Boost Users :

Subject: [Boost-users] Boost.Function and Boost.Bind
From: Yang Zhang (yanghatespam_at_[hidden])
Date: 2008-11-20 04:40:15

I have the following simple test case:

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
using namespace boost;
using namespace std;
void show(int x) { cout << x << endl; }
void twice(function0<void> f) { f(); f(); }
int main() {
   // This works...
   function<void()> f = bind(show, 0);
   bind(twice, f)();
   // ...but this does not compile.
   // bind(twice, bind(show, 0))();
   return 0;

When uncommenting the problematic line and attempting to build, I get:

$ g++ -Wall -o boost_function{,.cc}
/opt/armed/include/boost/bind.hpp: In member function ‘void
boost::_bi::list1<A1>::operator()(boost::_bi::type<void>, F&, A&, int)
[with F = void (*)(boost::function0<void,
std::allocator<boost::function_base> >), A = boost::_bi::list0, A1 =
boost::_bi::bind_t<void, void (*)(int),
boost::_bi::list1<boost::_bi::value<int> > >]’:
/opt/armed/include/boost/bind/bind_template.hpp:20: instantiated from
‘typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R, F,
L>::operator()() [with R = void, F = void (*)(boost::function0<void,
std::allocator<boost::function_base> >), L =
boost::_bi::list1<boost::_bi::bind_t<void, void (*)(int),
boost::_bi::list1<boost::_bi::value<int> > > >]’ instantiated from here
/opt/armed/include/boost/bind.hpp:232: error: conversion from ‘void’ to
non-scalar type ‘boost::function0<void,
std::allocator<boost::function_base> >’ requested

Why can't I put the two on the same line? (I also tried using
template<typename T> void twice(T f) { f(); f() }, but that didn't work
either.) Thanks in advance for any tips.

Yang Zhang

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at