Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-03-27 22:53:21


On Sun, Mar 27, 2011 at 11:35 AM, Thomas Heller
<thom.heller_at_[hidden]> wrote:
> On Sunday, March 27, 2011 05:43:39 PM Lorenzo Caminiti wrote:
>> On Sun, Mar 27, 2011 at 10:07 AM, Thomas Heller
>> <thom.heller_at_[hidden]> wrote:
>> > The guy who wrote the code could have said: const int factor = 10;
> assignment
>> > would then be impossible^W not allowed.
>>
>> Yes, but the use case would be to have factor const *only* within the
>> "function" passed to for_each while keeping it mutable in the
>> enclosing scope. Therefore, programmers have to declare factor
>> not-const within main() and I was wondering if there was a way using
>> Phoenix to add the const only locally within the "function" passed to
>> for_each (this is done by Boost.Loccal using "constant-binding" as in
>> `const bind& factor`).
>
> Oh right, you can do that ...:
>
> let(_a = ref(factor))[...]; // <-- bind as non-const reference
> let(_a = cref(factor))[...]; // <-- bind as const reference

Yes, I think that is what I was looking for. I will add it to the
Boost.Phoenix example.

BTW, can I do the same with Boost.Lambda?

Thanks,

--
Lorenzo

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk