00001
00002
00003 #ifndef OSL_MISC_REORDER_H
00004 #define OSL_MISC_REORDER_H
00005 #include <algorithm>
00006
00007 namespace osl
00008 {
00009 namespace misc
00010 {
00011 struct Reorder
00012 {
00014 template <class RandomIterator, class OrderArray>
00015 static void reorder(RandomIterator first, RandomIterator last,
00016 const OrderArray& indices)
00017 {
00018 const int size = last - first;
00019 for (int i=0; i<size-1; ++i)
00020 {
00021 int swap_target = indices[i];
00022 while (swap_target < i)
00023 swap_target = indices[swap_target];
00024 std::swap(*(first+i), *(first+swap_target));
00025 }
00026 }
00027 };
00028 }
00029 }
00030
00031 #endif
00032
00033
00034
00035