Opened 11 years ago
Closed 11 years ago
#5741 closed Feature Requests (fixed)
Declare sequence_index as non-copyable
Reported by: | Owned by: | Joaquín M López Muñoz | |
---|---|---|---|
Milestone: | To Be Determined | Component: | multi_index |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Based on this thread : http://lists.boost.org/boost-users/2011/07/69718.php
sequence_index should be declared as non-copyable to allow BOOST_FOREACH to iterate over it.
Michel Morin gave a solution: http://lists.boost.org/boost-users/2011/07/69722.php
namespace boost { namespace foreach { template<typename SuperMeta,typename TagList> struct is_noncopyable< boost::multi_index::detail::sequenced_index<SuperMeta, TagList> > : mpl::true_ {}; } }
Attachments (1)
Change History (5)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Other index types (ordered_index
, hashed_index
, random_access_index
)
also need this fix.
by , 11 years ago
Attachment: | multi_index_foreach_support_fix.patch added |
---|
A patch for hashed_index
, ordered_index
, random_access_index
and sequenced_index
(against trunk).
comment:3 by , 11 years ago
A patch attached, and here is a test case:
#include <iostream> #include <boost/multi_index_container.hpp> #include <boost/multi_index/hashed_index.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/random_access_index.hpp> #include <boost/multi_index/sequenced_index.hpp> #include <boost/foreach.hpp> #include <boost/range/value_type.hpp> template <typename Range> void display_range(Range const& rng) { BOOST_FOREACH(typename boost::range_value<Range>::type x, rng) { std::cout << x << std::endl; } } int main (int argc, char* argv[]) { using namespace boost::multi_index; multi_index_container<int, indexed_by< hashed_unique<identity<int> > , hashed_non_unique<identity<int> > , ordered_unique<identity<int> > , ordered_non_unique<identity<int> > , random_access<> , sequenced<> > > cont; display_range(cont.get<0>()); display_range(cont.get<1>()); display_range(cont.get<2>()); display_range(cont.get<3>()); display_range(cont.get<4>()); display_range(cont.get<5>()); return 0; }
Without the patch, this test fails to compile on compilers that use
BOOST_FOREACH_RUN_TIME_CONST_RVALUE_DETECTION
, such as gcc-4.6 and clang (both in C++03 mode).
Follow up:
The fix (to tell
BOOST_FOREACH
to avoid copingsequenced_index
) needs forward declaration offoreach::is_noncopyable
.