Explorar o código

improved sort

Michele Caini %!s(int64=7) %!d(string=hai) anos
pai
achega
d57e55b719

+ 5 - 3
src/entt/core/algorithm.hpp

@@ -26,13 +26,15 @@ struct StdSort {
      *
      * @tparam It Type of random access iterator.
      * @tparam Compare Type of comparison function object.
+     * @tparam Args Types of arguments to forward to the sort function.
      * @param first An iterator to the first element of the range to sort.
      * @param last An iterator past the last element of the range to sort.
      * @param compare A valid comparison function object.
+     * @param args Arguments to forward to the sort function, if any.
      */
-    template<typename It, typename Compare = std::less<>>
-    void operator()(It first, It last, Compare compare = Compare{}) const {
-        std::sort(std::move(first), std::move(last), std::move(compare));
+    template<typename It, typename Compare = std::less<>, typename... Args>
+    void operator()(It first, It last, Compare compare = Compare{}, Args &&... args) const {
+        std::sort(std::forward<Args>(args)..., std::move(first), std::move(last), std::move(compare));
     }
 };
 

+ 5 - 3
src/entt/entity/registry.hpp

@@ -1057,13 +1057,15 @@ public:
      * @tparam Component Type of components to sort.
      * @tparam Compare Type of comparison function object.
      * @tparam Sort Type of sort function object.
+     * @tparam Args Types of arguments to forward to the sort function object.
      * @param compare A valid comparison function object.
      * @param sort A valid sort function object.
+     * @param args Arguments to forward to the sort function object, if any.
      */
-    template<typename Component, typename Compare, typename Sort = StdSort>
-    void sort(Compare compare, Sort sort = Sort{}) {
+    template<typename Component, typename Compare, typename Sort = StdSort, typename... Args>
+    void sort(Compare compare, Sort sort = Sort{}, Args &&... args) {
         assure<Component>();
-        pool<Component>().sort(std::move(compare), std::move(sort));
+        pool<Component>().sort(std::move(compare), std::move(sort), std::forward<Args>(args)...);
     }
 
     /**

+ 5 - 3
src/entt/entity/sparse_set.hpp

@@ -1011,17 +1011,19 @@ public:
      *
      * @tparam Compare Type of comparison function object.
      * @tparam Sort Type of sort function object.
+     * @tparam Args Types of arguments to forward to the sort function object.
      * @param compare A valid comparison function object.
      * @param sort A valid sort function object.
+     * @param args Arguments to forward to the sort function object, if any.
      */
-    template<typename Compare, typename Sort = StdSort>
-    void sort(Compare compare, Sort sort = Sort{}) {
+    template<typename Compare, typename Sort = StdSort, typename... Args>
+    void sort(Compare compare, Sort sort = Sort{}, Args &&... args) {
         std::vector<size_type> copy(instances.size());
         std::iota(copy.begin(), copy.end(), 0);
 
         sort(copy.begin(), copy.end(), [this, compare = std::move(compare)](const auto lhs, const auto rhs) {
             return compare(const_cast<const object_type &>(instances[rhs]), const_cast<const object_type &>(instances[lhs]));
-        });
+        }, std::forward<Args>(args)...);
 
         for(size_type pos = 0, last = copy.size(); pos < last; ++pos) {
             auto curr = pos;