captureSort.h
Go to the documentation of this file.
00001 /* captureSort.h
00002  */
00003 #ifndef MOVE_ORDER_CAPTURESORT_H
00004 #define MOVE_ORDER_CAPTURESORT_H
00005 
00006 #include "osl/move.h"
00007 #include <algorithm>
00008 namespace osl
00009 {
00010 namespace move_order
00011 {
00015   struct CaptureSort
00016   {
00017     template <class Iterator>
00018     static void sort(Iterator first, Iterator last)
00019     {
00020       while (first < --last)
00021       {
00022         while (true)
00023         {
00024           if (first->capturePtype() == PTYPE_EMPTY)
00025             break;
00026           ++first;
00027           if (! (first < last))
00028             return;
00029         }
00030         assert(first->capturePtype() == PTYPE_EMPTY);
00031         while (true)
00032         {
00033           if (! (first < last))
00034             return;
00035           if (last->capturePtype() != PTYPE_EMPTY)
00036             break;
00037           --last;
00038         }
00039         assert(last->capturePtype() != PTYPE_EMPTY);
00040         assert(first < last);
00041         std::swap(*first, *last);
00042         ++first;
00043       }
00044     }
00045   };
00046 } // namespace move_order
00047   using move_order::CaptureSort;
00048 } // namespace osl
00049 
00050 #endif /* MOVE_ORDER_CAPTURESORT_H */
00051 // ;;; Local Variables:
00052 // ;;; mode:c++
00053 // ;;; c-basic-offset:2
00054 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines