[Multi-index] : code fail to compile with VS2010 and boost 1.46.1. Proposed workaround
Hello, I had some code using boost 1.46.1 Multi-index library that used to compile and work very well with VS2008. I recently turned to VS2010 and some code is not compiling anymore. The problem is located in the boost_1_46_1\boost\multi_index\composite_key.hpp file and the compiler complains about not being able to distinguish between ambiguous overloads... I had to modify the composite_key.hpp file and have following changes : line 1001 : //return operator()(x,make_tuple(cref(y))); return operator()(x,make_tuple(boost::cref(y))); line 1036 : //return operator()(make_tuple(cref(x)),y); return operator()(make_tuple(boost::cref(x)),y); In order to explicitely add the boost namespace for cref. With those changes, it do compile and works very well. Can those changes in composite_key.hpp break something else ? Is there another workaround I would have missed ? I'm suspecting some conflict with new TR1 things i'm not very familiar with... Best regards, Mathieu Peyréga
I had to modify the composite_key.hpp file and have following changes :
line 1001 : //return operator()(x,make_tuple(cref(y))); return operator()(x,make_tuple(boost::cref(y)));
line 1036 : //return operator()(make_tuple(cref(x)),y); return operator()(make_tuple(boost::cref(x)),y);
In order to explicitely add the boost namespace for cref.
With those changes, it do compile and works very well. Can those changes in composite_key.hpp break something else ? Is there another workaround I would have missed ? I'm suspecting some conflict with new TR1 things i'm not very familiar
Perhaps, you have "using namespace std;" directive somewhere before you include this header?
Hello, I've just been checking and could not find any "using namespace std" statement in any of the includes... I've even been checking with reverting to genuine composite_key file and adding an explicit namespace boost { } using namespace boost; before the includes in my cpp file which appear in the following order : #include <boost/multi_index_container.hpp> #include <boost/multi_index/tag.hpp> #include <boost/multi_index/indexed_by.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/composite_key.hpp> Adding this directive do not solve the issue... Regards, Mathieu Peyréga Le 02/05/2011 13:07, Igor R a écrit :
I had to modify the composite_key.hpp file and have following changes :
line 1001 : //return operator()(x,make_tuple(cref(y))); return operator()(x,make_tuple(boost::cref(y)));
line 1036 : //return operator()(make_tuple(cref(x)),y); return operator()(make_tuple(boost::cref(x)),y);
In order to explicitely add the boost namespace for cref.
With those changes, it do compile and works very well. Can those changes in composite_key.hpp break something else ? Is there another workaround I would have missed ? I'm suspecting some conflict with new TR1 things i'm not very familiar
Perhaps, you have "using namespace std;" directive somewhere before you include this header? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Here is an example of the described behaviour Here, it does not compile with non modified composite_key.hpp file, and do compile with modified file. Regards, Mathieu Peyréga ----------------------------- test_multi_index.cpp ----------------------------- #include <string> #include <boost/multi_index_container.hpp> #include <boost/multi_index/tag.hpp> #include <boost/multi_index/indexed_by.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/composite_key.hpp> using namespace boost; using namespace boost::multi_index; class GPS_Station { public: GPS_Station(void); GPS_Station(GPS_Station const& station); GPS_Station& operator=(GPS_Station const& station); ~GPS_Station(void); unsigned long m_Id; std::string m_Name; std::string m_DomeNumber; double m_Epoch; double m_X_ECEF; double m_Y_ECEF; double m_Z_ECEF; }; class CTestMultiIndex { public: // Tags pour l'utilisation du multi-index container de Boost en mode "Tag" typedef composite_key<GPS_Station, member<GPS_Station,unsigned long,&GPS_Station::m_Id>, member<GPS_Station,double,&GPS_Station::m_Epoch> > by_id_and_epoch; typedef composite_key<GPS_Station, member<GPS_Station,unsigned long,&GPS_Station::m_Id>, member<GPS_Station,double,&GPS_Station::m_Epoch> > by_id_and_epoch; typedef composite_key<GPS_Station, member<GPS_Station,std::string,&GPS_Station::m_Name>, member<GPS_Station,double,&GPS_Station::m_Epoch> > by_name_and_epoch; typedef composite_key<GPS_Station, member<GPS_Station,std::string,&GPS_Station::m_DomeNumber>, member<GPS_Station,double,&GPS_Station::m_Epoch> > by_domenumber_and_epoch; typedef composite_key<GPS_Station, member<GPS_Station,double,&GPS_Station::m_Epoch>, member<GPS_Station,unsigned long,&GPS_Station::m_Id> > by_epoch_and_id; typedef composite_key<GPS_Station, member<GPS_Station,double,&GPS_Station::m_Epoch>, member<GPS_Station,std::string,&GPS_Station::m_Name> > by_epoch_and_name; typedef composite_key<GPS_Station, member<GPS_Station,double,&GPS_Station::m_Epoch>, member<GPS_Station,std::string,&GPS_Station::m_DomeNumber> > by_epoch_and_domenumber; typedef multi_index_container<GPS_Station, indexed_by<ordered_non_unique<by_id_and_epoch>, ordered_non_unique<by_name_and_epoch>, ordered_non_unique<by_domenumber_and_epoch>, ordered_unique<by_epoch_and_id>, ordered_unique<by_epoch_and_name>, ordered_unique<by_epoch_and_domenumber> > > DataSetType; typedef nth_index<DataSetType,0>::type dataset_by_id_and_epoch; typedef nth_index<DataSetType,1>::type dataset_by_name_and_epoch; typedef nth_index<DataSetType,2>::type dataset_by_domenumber_and_epoch; typedef nth_index<DataSetType,3>::type dataset_by_epoch_and_id; typedef nth_index<DataSetType,4>::type dataset_by_epoch_and_name; typedef nth_index<DataSetType,5>::type dataset_by_epoch_and_domenumber; void fail_to_compile(DataSetType& dataset, std::string const& stationname, std::string const& prefix); }; // class CTestMultiIndex void CTestMultiIndex::fail_to_compile(DataSetType& dataset, std::string const& stationname, std::string const& prefix) { const dataset_by_name_and_epoch &datasetbynameandepoch = get<1>(dataset); std::pair<dataset_by_name_and_epoch::iterator, dataset_by_name_and_epoch::iterator> range = datasetbynameandepoch.equal_range(stationname); }
The same, but a bit shorter: #include <string> #include <boost/multi_index_container.hpp> #include <boost/multi_index/indexed_by.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/composite_key.hpp> using namespace boost::multi_index; struct record { std::string str_; }; struct test { public: typedef composite_key<record, member<record, std::string, &record::str_>
key;
typedef multi_index_container<record, indexed_by<ordered_non_unique<key> >
container;
void fail_to_compile() { container c; std::string val = "abcd"; c.equal_range(val); } };
Igor R <boost.lists <at> gmail.com> writes:
The same, but a bit shorter: [...]
Although I can'r reproduce the behavior (I don't have VS2010 here) this is no doubt produced by ADL ambiguities between std::ref(broght in by std::string in this example) and boost::ref. The change at https://svn.boost.org/trac/boost/changeset/71671 should fix this. Can you please check out before I merge to the release branch? Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Hello, your modified version works for me with Visual Studio 2010 sp1 and boost 1.46.1 Regards, Mathieu Peyréga Le 02/05/2011 17:10, Joaquin M Lopez Munoz a écrit :
Igor R <boost.lists <at> gmail.com> writes:
The same, but a bit shorter: [...] Although I can'r reproduce the behavior (I don't have VS2010 here) this is no doubt produced by ADL ambiguities between std::ref(broght in by std::string in this example) and boost::ref.
The change at
https://svn.boost.org/trac/boost/changeset/71671
should fix this. Can you please check out before I merge to the release branch?
Thank you,
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
The same, but a bit shorter: [...]
Although I can'r reproduce the behavior (I don't have VS2010 here) this is no doubt produced by ADL ambiguities between std::ref(broght in by std::string in this example) and boost::ref.
The change at
https://svn.boost.org/trac/boost/changeset/71671
should fix this. Can you please check out before I merge to the release branch?
Yes, it seems to be ok. Thanks.
participants (3)
-
Igor R
-
Joaquin M Lopez Munoz
-
Mathieu Peyréga