|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-06-25 06:44:05
Ian wrote:
> Markus
>
> Thanks for the reply, but no dice. The idea was to use the address of
> the current item as a quick and dirty counter modular counter,
> However this code:
>
> std::for_each(begin, end,
> l::_1 = l::ll_static_cast<int>(_1) % 3);
>
> does not take the address but the items value, and unfortunately this:
>
> std::for_each(begin, end,
> l::_1 = l::ll_static_cast<int>(&_1) % 3);
>
> does not compile. Now I could get a bit more realistic and just code
> the thing a bit cleaner like this:
>
> int x = 0;
> for_each( lookup_, lookup_ + (sizeof(lookup_) / sizeof(unsigned
> int)), _1 = ++var(x) % 3
> );
>
> But that's kinda skirting around the real issue which is, if I can't
> use lambda to *directly* replace code that is trivial with a hand
> written loop, what chance when the complexity is raised a bit?
It is a feature that your original (nonportable) code cannot be replaced by
a lambda expression. Why not just use the correct version? Or even better:
template<class T, size_t N> size_t array_size(T (&a) [N]) { return N; }
int x = 0;
std::generate_n(lookup_, array_size(lookup_), ++ll::var(x) % 3);
You can even get rid of x by using
std::generate_n(lookup_, array_size(lookup_), boost::bind<int>(++ll::_1 % 3,
0));
if you are using the CVS version of boost::bind; 1.30 doesn't approximate
http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1438.htm
well.
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