All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
reorder.h
Go to the documentation of this file.
1 /* reorder.h
2  */
3 #ifndef OSL_MISC_REORDER_H
4 #define OSL_MISC_REORDER_H
5 #include <algorithm>
6 
7 namespace osl
8 {
9  namespace misc
10  {
11  struct Reorder
12  {
14  template <class RandomIterator, class OrderArray>
15  static void reorder(RandomIterator first, RandomIterator last,
16  const OrderArray& indices)
17  {
18  const int size = last - first;
19  for (int i=0; i<size-1; ++i) // we do not need to swap the last one
20  {
21  int swap_target = indices[i];
22  while (swap_target < i)
23  swap_target = indices[swap_target];
24  std::swap(*(first+i), *(first+swap_target));
25  }
26  }
27  };
28  }
29 }
30 
31 #endif /* OSL_MISC_REORDER_H */
32 // ;;; Local Variables:
33 // ;;; mode:c++
34 // ;;; c-basic-offset:2
35 // ;;; End: