reorder.h
Go to the documentation of this file.
00001 /* reorder.h
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)    // we do not need to swap the last one
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 /* OSL_MISC_REORDER_H */
00032 // ;;; Local Variables:
00033 // ;;; mode:c++
00034 // ;;; c-basic-offset:2
00035 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines