Boost logo

Boost Users :

From: Shawn Church (sl_church_at_[hidden])
Date: 2004-01-29 01:48:07


I may be missing something simple here but I have tried everything I can think
of
and cannot get the following to work (simplified from a project I am working
on):

Given a class such as:

class foo{

public:
foo(const char* name): _name(name) {}
const char* name() const {return _name.c_str();}

private:
std::string _name;};

I can do the following without any problems:

std::vector<foo> Foos;
...
for_each(Foos.begin(), Foos.end(),cout << bind(&foo::name, _1) << "|");

This prints a list of all the names in the vector of Foo objects by calling
the Foo::name() method. It would be nice to be able to do something like the
following:

for_each(Foos.begin(), Foos.end(), cout << format("%-10s|") % bind(&foo::name,
_1);

I have tried everything I can think of including extending the return type
deduction of the lambda library to include the "%" operator as used by format
and binding directly to the basic_format::operator% method. In every case I
get 40 or so compile errors explaining why my 30 character statement is wrong
:-)

Does anyone have an example of this usage that works? This is not a high
priority as I can obviously just format the value returned by the Foo::name()
method but it would be nice to have this technique available when the need
arises.

I adapated the code above from a test program that demonstrates the problem in
detail. I can provide the test program if anyone is interested (just tell me
what to do with it).

Thankyou for any help you can provide,

Shawn Church
sl_church_at_sbc_global.net


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net