Boost logo

Boost Users :

From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-04-30 15:44:07


At first glance, it looked like the multi_index lib (perhaps combined
with the range lib) might provide a convenient way to search for
ranges of two+ indicies. For example, points. You have a grid of
random points and you want a pair of iterators that contain all points
within the cube (x1,y1,z1) and (x2,y2,z2) .

I made a multi_index container with a composite key containing all
three coords contained within a point class.

struct point {
  int x, y ,z;
};

struct coords_key : composite_key<
  point,
  member<point,int,x>,
  member<point,int,y>,
  member<point,int,z>
>{};

struct coords{};

typedef multi_index_container<
  point,
  indexed_by<
    ordered_non_unique<tag<coords>, coords_key>
>
> point_set;

int main() {
  point_set p;

  p.insert(point(1,2,2));
  p.insert(point(2,3,1));
  p.insert(point(1,2,3));
  p.insert(point(10,3,2));

  point_set::iterator it = p.lower_bound(make_tuple(1,1,1));
  point_set::iterator it2 = p.upper_bound(make_tuple(3,3,3));
  return 0;
}

it would be great if [it, it2] contained the first four points, but
this is not the case. If I run this code, it == it2 == the first
point.

Am i barking up the wrong tree? Or is this doable.

Cheers,
Chris


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