c++boostboost-bindboost-foreach

solving issue # C++98 Valid use of “for_each” in the code using Boost library 1.53 or 1.56


I already asked the question. I am wondering if there is any solution for this using boost::for_each and boost::bind.

The question has been already answered, that's why I created another issue here; only for the curiosity. Thanks.


Solution

  • Yes, you can use boost::bind to create a suitable functor, with a placeholder for the functor's parameter:

    for_each(oldpnTs.begin(), oldpnTs.end(), bind(typeDetection, _1, ALL, *this));
    

    In modern C++, I'd prefer a new-style loop

    for (pnt & p : oldpnTs) {
        typeDetection(p, ALL, *this);
    }