All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
captureSort.h
Go to the documentation of this file.
1 /* captureSort.h
2  */
3 #ifndef MOVE_ORDER_CAPTURESORT_H
4 #define MOVE_ORDER_CAPTURESORT_H
5 
6 #include "osl/move.h"
7 #include <algorithm>
8 namespace osl
9 {
10 namespace move_order
11 {
15  struct CaptureSort
16  {
17  template <class Iterator>
18  static void sort(Iterator first, Iterator last)
19  {
20  while (first < --last)
21  {
22  while (true)
23  {
24  if (first->capturePtype() == PTYPE_EMPTY)
25  break;
26  ++first;
27  if (! (first < last))
28  return;
29  }
30  assert(first->capturePtype() == PTYPE_EMPTY);
31  while (true)
32  {
33  if (! (first < last))
34  return;
35  if (last->capturePtype() != PTYPE_EMPTY)
36  break;
37  --last;
38  }
39  assert(last->capturePtype() != PTYPE_EMPTY);
40  assert(first < last);
41  std::swap(*first, *last);
42  ++first;
43  }
44  }
45  };
46 } // namespace move_order
47  using move_order::CaptureSort;
48 } // namespace osl
49 
50 #endif /* MOVE_ORDER_CAPTURESORT_H */
51 // ;;; Local Variables:
52 // ;;; mode:c++
53 // ;;; c-basic-offset:2
54 // ;;; End: