Boost logo

Boost :

Subject: [boost] [local] Help for the Alternatives section
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-03-26 18:19:46

Hello all,

I am updating Boost.Local docs and I could use a some help in getting
the Alternatives section right

How can I program the following code (its local function and `factor`
constant binding) using Boost.Phoenix, Boost.Lambda, and C++0x lambda
functions? If you know, can you please reply with the actual code?

#include <boost/local/function.hpp>
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    double sum = 0.0;
    int factor = 10;

    void BOOST_LOCAL_FUNCTION_PARAMS(double num,
            // Variable `factor` bound as constant.
            bind& sum, const bind& factor) {
        sum += factor * num;
        std::cout << "Summed: " << sum << std::endl;

    std::vector<double> v(3);
    v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;
    // Local function `add` passed as template parameter.
    std::for_each(v.begin(), v.end(), add);
    return 0;

Thank you very much!


Boost list run by bdawes at, gregod at, cpdaniel at, john at