Boost logo

Boost Users :

From: Daniel James (daniel_james_at_[hidden])
Date: 2006-03-08 17:08:28


On 3/8/06, Scott Meyers <usenet_at_[hidden]> wrote:
> This looks like it should be lambda-able. Here's my attempt:
>
> for_each(fs::directory_iterator(dir), fs::directory_iterator(),
> if_then_else(bind(&fs::is_directory, _1),
> cout << "D\n",
> cout << "~D\n"));
>
> VC7.1 doesn't like this -- the diagnostics are below. Any idea how I can make
> this work?

Try out:

    for_each(fs::directory_iterator(dir), fs::directory_iterator(),
             if_then_else(bind(&fs::is_directory, _1),
                          cout << constant("D\n"),
                          cout << constant("~D\n")));

The problem is that 'cout << "D\n"' is getting called immediately - as
it's not a lambda expression, by making "D\n" a delayed constant it
becomes one. This is documented at http://tinyurl.com/7jq3v.

Hope that helps,

Daniel


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