I have the following simple test case:
#include
#include
#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 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::function0boost::function_base >), A = boost::_bi::list0, A1 =
boost::_bi::bind_t >]’:
/opt/armed/include/boost/bind/bind_template.hpp:20: instantiated from
‘typename boost::_bi::result_traits::type boost::_bi::bind_t::operator()() [with R = void, F = void (*)(boost::function0boost::function_base >), L =
boost::_bi::list1 > >]’
boost_function.cc:13: instantiated from here
/opt/armed/include/boost/bind.hpp:232: error: conversion from ‘void’ to
non-scalar type ‘boost::function0boost::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
http://www.mit.edu/~y_z/