
Hi, I use BOOST_FOREACH to iterate of a BMI with a sequence index. The code used to work with Boost 1.46 and before, but broke with Boost 1.47. Am I doing something wrong ? ------------------------ #include <iostream> # include <boost/multi_index/hashed_index.hpp> # include <boost/multi_index/member.hpp> # include <boost/multi_index/sequenced_index.hpp> # include <boost/multi_index_container.hpp> # include <boost/foreach.hpp> using namespace ::boost::multi_index; typedef multi_index_container< int, indexed_by< sequenced<> > > bmi_t; typedef bmi_t::nth_index<0>::type seq_idx; const seq_idx& ret(const seq_idx& idx) { return idx; } int main() { bmi_t b; seq_idx& seq = b.get<0>(); // Works BOOST_FOREACH (int i, seq) std::cout << i << std::endl; // Doesn't compile BOOST_FOREACH (int i, ret(seq)) std::cout << i << std::endl; } ------------------------ Note that the offending part is the 'ret(seq)', without it, the code compiles. The error with g++ 4.6.1 is:
In file included from bmi.cc:9:0: /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp: In destructor ‘boost::foreach_detail_::simple_variant<T>::~simple_variant() [with T = boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> >]’: /home/yabo/dev/boost/usr/include/boost/foreach.hpp:256:8: instantiated from here /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp:561:3: error: ‘boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::~sequenced_index() [with SuperMeta = boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, TagList = boost::mpl::vector0<mpl_::na>]’ is protected /home/yabo/dev/boost/usr/include/boost/foreach.hpp:586:13: error: within this context /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp: In constructor ‘boost::foreach_detail_::simple_variant<T>::simple_variant(const T&) [with T = boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> >]’: /home/yabo/dev/boost/usr/include/boost/foreach.hpp:648:95: instantiated from ‘boost::foreach_detail_::auto_any<boost::foreach_detail_::simple_variant<T> > boost::foreach_detail_::contain(const T&, bool*) [with T = boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> >]’ bmi.cc:28:3: instantiated from here /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp:549:3: error: ‘boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::sequenced_index(const boost::multi_index::detail::sequenced_index<SuperMeta, TagList>&) [with SuperMeta = boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, TagList = boost::mpl::vector0<mpl_::na>]’ is protected /home/yabo/dev/boost/usr/include/boost/foreach.hpp:571:9: error: within this context /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp: In copy constructor ‘boost::foreach_detail_::simple_variant<T>::simple_variant(const boost::foreach_detail_::simple_variant<T>&) [with T = boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> >, boost::foreach_detail_::simple_variant<T> = boost::foreach_detail_::simple_variant<boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> > >]’: /home/yabo/dev/boost/usr/include/boost/foreach.hpp:256:8: instantiated from ‘boost::foreach_detail_::auto_any<boost::foreach_detail_::simple_variant<T> > boost::foreach_detail_::contain(const T&, bool*) [with T = boost::multi_index::detail::sequenced_index<boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, boost::mpl::vector0<mpl_::na> >]’ bmi.cc:28:3: instantiated from here /home/yabo/dev/boost/usr/include/boost/multi_index/sequenced_index.hpp:549:3: error: ‘boost::multi_index::detail::sequenced_index<SuperMeta, TagList>::sequenced_index(const boost::multi_index::detail::sequenced_index<SuperMeta, TagList>&) [with SuperMeta = boost::multi_index::detail::nth_layer<1, int, boost::multi_index::indexed_by<boost::multi_index::sequenced<> >, std::allocator<int> >, TagList = boost::mpl::vector0<mpl_::na>]’ is protected /home/yabo/dev/boost/usr/include/boost/foreach.hpp:578:13: error: within this context
Note that with clang++ 2.9 the code doesn't compile at all either with Boost 1.46 or Boost 1.47. Thanks! -- Maxime