Reputation: 440
I was trying using Boost Phoenix. My aim is to have stl algorithms that take a container instead of range of iterators, as described here. However, I am getting a mess of errors on a rather simple code:
#include <boost/phoenix/stl/algorithm.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
namespace phx = boost::phoenix;
int main(int argc, char ** argv) {
std::vector<int> my_arr{ 0, 1, 2, 3 };
phx::for_each(my_arr, [](int i){std::cout << i << std::endl; });
}
I tried it on two platforms (Win7, Ubuntu) where I otherwise use multiple parts of Boost.
The error messages are rather long so I put them in files:
I can't really make much of the errors apart from templates not being compiled correctly, but I guess I am missing something rather simple.
Upvotes: 2
Views: 206
Reputation: 1747
I think you are using the wrong boost library. The phoenix algorithms are lazy functions which are explained here. So phoenix::for_each
does not do anything if it is called, but returns a function object which iterates over the range once it is called. If you simply want to use the STL (and other) algorithms on ranges you can use the boost.range library:
#include <boost/range/algorithm/for_each.hpp>
#include <iostream>
#include <vector>
namespace rng = boost::range;
int main(int argc, char ** argv) {
std::vector<int> my_arr{ 0, 1, 2, 3 };
rng::for_each(my_arr, [](int i){std::cout << i << std::endl; });
}
Upvotes: 4
Reputation: 14129
You simply need to include the phoenix
core before including anything else.
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/stl/algorithm.hpp>
... rest of your program
Upvotes: 1