]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
container: allow sort_and_unique to have a comparator
authorJustin Viiret <justin.viiret@intel.com>
Thu, 16 Feb 2017 00:03:05 +0000 (11:03 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:04:31 +0000 (15:04 +1000)
src/rose/rose_build_bytecode.cpp
src/util/container.h

index 68e88971b568188cad23227774cd6db64a8cb9cf..0a872ae44c73fdb461296755e8234863b8c60f84 100644 (file)
@@ -3658,13 +3658,11 @@ void makeRoleInfixTriggers(RoseBuildImpl &build, build_context &bc,
     }
 
     // Order, de-dupe and add instructions to the end of program.
-    sort(begin(infix_program), end(infix_program),
-         [](const RoseInstrTriggerInfix &a, const RoseInstrTriggerInfix &b) {
-             return tie(a.cancel, a.queue, a.event) <
-                    tie(b.cancel, b.queue, b.event);
-         });
-    infix_program.erase(unique(begin(infix_program), end(infix_program)),
-                        end(infix_program));
+    sort_and_unique(infix_program, [](const RoseInstrTriggerInfix &a,
+                                      const RoseInstrTriggerInfix &b) {
+        return tie(a.cancel, a.queue, a.event) <
+               tie(b.cancel, b.queue, b.event);
+    });
     for (const auto &ri : infix_program) {
         program.add_before_end(make_unique<RoseInstrTriggerInfix>(ri));
     }
@@ -4163,13 +4161,10 @@ void makePushDelayedInstructions(const RoseBuildImpl &build,
         }
     }
 
-    sort(begin(delay_instructions), end(delay_instructions),
-         [](const RoseInstrPushDelayed &a, const RoseInstrPushDelayed &b) {
-             return tie(a.delay, a.index) < tie(b.delay, b.index);
-         });
-    delay_instructions.erase(
-        unique(begin(delay_instructions), end(delay_instructions)),
-        end(delay_instructions));
+    sort_and_unique(delay_instructions, [](const RoseInstrPushDelayed &a,
+                                           const RoseInstrPushDelayed &b) {
+        return tie(a.delay, a.index) < tie(b.delay, b.index);
+    });
 
     for (const auto &ri : delay_instructions) {
         program.add_before_end(make_unique<RoseInstrPushDelayed>(ri));
index e8a164189ec06026eda4e918b7bc3243a793b4a3..68f60e99eed6ac8bb7647d4e4dd1004f3230d8e3 100644 (file)
@@ -90,9 +90,9 @@ auto make_vector_from(const std::pair<It, It> &range)
 }
 
 /** \brief Sort a sequence container and remove duplicates. */
-template <typename C>
-void sort_and_unique(C &container) {
-    std::sort(std::begin(container), std::end(container));
+template <typename C, typename Compare = std::less<typename C::value_type>>
+void sort_and_unique(C &container, Compare comp = Compare()) {
+    std::sort(std::begin(container), std::end(container), comp);
     container.erase(std::unique(std::begin(container), std::end(container)),
                     std::end(container));
 }