Boost logo

Boost Users :

Subject: [Boost-users] joining boost ranges in loop
From: Ernest Zaslavsky (ernest.zaslavsky_at_[hidden])
Date: 2015-02-04 14:18:56


Actually the question is how to achieve it? The use of boost::any_range is possible but undesirable (performance considerations)
Sample code:
typedef boost::multi_index_container<
    int, bmi::indexed_by<bmi::hashed_unique<bmi::tag<struct someTag>,
                                            bmi::identity<int>>>> Datum;

class bar {
public:
  auto foo() const;

private:
  Datum m_someDataContainer;
};
SomeType bar::foo() const {
  SomeType retVal;
  for (auto i = 0u; i < 10; ++i) {
    retVal = boost::range::join(retVal, m_someDataContainer.equal_range(i));
  }
  return retVal;
}

Here we can observe several problems. The return type cannot be easily deduced. The join would create joined_range<joined_range<joined_range and so on of nested types. The above can be achieved by using any_range like
typedef boost::any_range<int, boost::random_access_traversal_tag, int&, std::ptrdiff_t> VersionRange;
but above will create nested joined_range of any_range which, when the number of iterations is big enough, has tremendous impact on performance.
So, what can be done here?



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net