Boost logo

Boost Users :

Subject: [Boost-users] Using boost function input iterator with class member functions
From: Michael King (wmichaelking1_at_[hidden])
Date: 2011-09-04 22:29:39


I am trying to use a class member function in conjunction with boost's
function input iterator, and am having trouble coming up with a solution
which can in any way be considered elegant...

My initial thought process was to do something like :

    // does not work because the functor (1st arg to make_function_input
iterator ) cannot be temporary... or something like that
    std::ostream_iterator<result_type>(std::cout, " ")
However, this fails as noted above.
Thus, i had to look at some compiler error messages in order to figure out
the return type of boost::bind and create some boost::bind object producing
the working code below, however, this looks pretty terrible.

Can anyone suggest a more convenient solution to the problem I am trying to

Michael King


class foo {
    typedef double result_type;
    result_type return_random() const { return drand48(); }

int main() {
  foo bar;
  // found type from compiler error message...
> f = boost::bind(&foo::return_random, bar);

    boost::make_function_input_iterator(f, 1),
    boost::make_function_input_iterator(f, 10),
    std::ostream_iterator<double>(std::cout, "\n")

  return 0;

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