
Filip Konvi?ka ha escrito:
Hi,
getting lambda work with multi_index seems a bit tough for me.... the following compiles fine with MSVC++ 2003, but not when I #include sequenced_index.hpp or ordered_index.hpp.
The error message says: error C2872: '_1' : ambiguous symbol could be 'c:\Boost\include\boost-1_33_1\boost\lambda\core.hpp(69) : const boost::lambda::placeholder1_type &boost::lambda::`anonymous-namespace'::_1' or 'c:\Boost\include\boost-1_33_1\boost\bind\placeholders.hpp(42) : boost::arg<I> `anonymous-namespace'::_1' with [ I=1 ]
Hello Filip, the problem you describe is only incidentally related with Boost.MultiIndex (anyway, thank you for using the lib!): actually, it's a manifestation of a symbol clash between Boost.Lambda and Boost.Bind: #include <boost/config.hpp> #include <boost/lambda/lambda.hpp> #include <boost/bind.hpp> #include <list> using namespace boost; using namespace boost::lambda; int main(int argc, char* argv[]) { std::list<int> v(10); for_each(v.begin(), v.end(), _1 = 1); return 0; } You're having the error under the conditions you describe just because boost/multi_index/sequenced_index.hpp and boost/multi_index/ordered_index.hpp internally include boost/bind.hpp.
This can of course be fixed by using boost::lambda::_1, but I doubt that it is the expected behavior.
I guess the using declaration is a perfectly good solution if you don't use Boost.Bind in the offending translation unit: This is a well known problem with Boost.Bind defining its placeholders in an unnamed space (::_1,::_2,...), which causes ambiguity problems when combined with the "using namespace boost::lambda" directive. You might want to read the following thread for further info on the issue: http://lists.boost.org/Archives/boost/2004/11/76822.php AFAIK this is not currently being addressed in any way.
Can anyone please explain what I'm doing wrong?
HTH, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo