Opened 11 years ago

Closed 11 years ago

#5741 closed Feature Requests (fixed)

Declare sequence_index as non-copyable

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

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

Download all attachments as: .zip

Change History (5)

comment:1 by Michel MORIN <mimomorin@…>, 11 years ago

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 by Michel MORIN <mimomorin@…>, 11 years ago

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

by Michel MORIN <mimomorin@…>, 11 years ago

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

comment:3 by Michel MORIN <mimomorin@…>, 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).

comment:4 by Joaquín M López Muñoz, 11 years ago

Resolution: fixed
Status: newclosed

(In [73498]) fixed #5741

Note: See TracTickets for help on using tickets.