Boost logo

Boost Users :

From: Jaakko Järvi (jajarvi_at_[hidden])
Date: 2005-04-27 13:13:48


Hi Matthias,

On Apr 17, 2005, at 4:17 AM, Matthias Kaeppler wrote:

> Hi,
>
> in my program, I have this function to compute the sum of sizes of a
> bunch of files:
>
> Glib::ustring DirBrowser::get_total_file_size()
> {
> using namespace boostfs; // boostfs = boost::filesystem
> using namespace lambda; // lambda = boost::lambda
> boost::intmax_t sum = 0;
>
> std::for_each(m_first_file,m_files.end(),sum+=bind(&file_size,*_1));
> return make_size_human_readable( sum );
> }

> The line with for_each computes the sum of file sizes, by iterating
> over a container of pointers to boostfs::pathS, starting at the first
> file (there are also directories, before the files), till the end,
> invoking the lambda functor on each.
>
> Since this method does not change the state of the object, I wanted to
> declare it const, but suddenly the lambda expression starts
> complaining:
> Somehow, those path objects inside the lambda expression become const
> now, too, and it doesn't compile anymore.
>

You mean you are making get_total_file_size to be a const member
function?
Are m_first_file, and m_files members of DirBrowser?

If so, this most likely makes *_1 (with a path object substituted for
_1) return a const object.
How does file_size take its argument? By non-const reference perhaps?
If so, then that would be a reason.

If this reasoning does not hold, can you provide some more context?

   Best, Jaakko Järvi

> How come?
>
> --
> Matthias Kaeppler
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
-- Jaakko Järvi, Assistant Professor
-- Texas A&M University, Computer Science
-- jarvi_at_[hidden]


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