Modify

Ticket #5741 (closed Feature Requests: fixed)

Opened 3 years ago

Last modified 3 years ago

Declare sequence_index as non-copyable

Reported by: Maxime van Noppen <maxime@…> Owned by: joaquin
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

multi_index_foreach_support_fix.patch Download (3.6 KB) - added by Michel MORIN <mimomorin@…> 3 years ago.
A patch for hashed_index, ordered_index, random_access_index and sequenced_index (against trunk).

Change History

comment:1 Changed 3 years ago by Michel MORIN <mimomorin@…>

Follow up:

The fix (to tell BOOST_FOREACH to avoid coping sequenced_index) needs forward declaration of foreach::is_noncopyable.

namespace boost{ namespace foreach{

template<typename T> struct is_noncopyable; // forward declaration

template<typename SuperMeta,typename TagList>
struct is_noncopyable<
  multi_index::detail::sequenced_index<SuperMeta, TagList>
>:mpl::true_
{
};

}}

comment:2 Changed 3 years ago by Michel MORIN <mimomorin@…>

Other index types (ordered_index, hashed_index, random_access_index) also need this fix.

Changed 3 years ago by Michel MORIN <mimomorin@…>

A patch for hashed_index, ordered_index, random_access_index and sequenced_index (against trunk).

comment:3 Changed 3 years ago by Michel MORIN <mimomorin@…>

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).

comment:4 Changed 3 years ago by joaquin

  • Status changed from new to closed
  • Resolution set to fixed

(In [73498]) fixed #5741

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.