PIString::arg() now ignore non-suitable %.

PIVector and PIDeque now use std::stable_sort
This commit is contained in:
2024-12-07 12:57:48 +03:00
parent 9e08b6ffc5
commit 79007e7b4e
3 changed files with 13 additions and 13 deletions

View File

@@ -1494,11 +1494,11 @@ public:
//! \~\details //! \~\details
//! \~english The order of equal elements is not guaranteed to be preserved. //! \~english The order of equal elements is not guaranteed to be preserved.
//! Elements are compared using operator<. //! Elements are compared using operator<.
//! Sorting provided by [std::sort](https://en.cppreference.com/w/cpp/algorithm/sort). //! Sorting provided by [std::stable_sort](https://en.cppreference.com/w/cpp/algorithm/stable_sort).
//! Complexity `O(N·log(N))`. //! Complexity `O(N·log(N))`.
//! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется. //! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется.
//! Для сравнения элементов используется оператор `operator<`. //! Для сравнения элементов используется оператор `operator<`.
//! Для сортировки используется функция [std::sort](https://ru.cppreference.com/w/cpp/algorithm/sort). //! Для сортировки используется функция [std::stable_sort](https://ru.cppreference.com/w/cpp/algorithm/stable_sort).
//! Сложность сортировки `O(N·log(N))`. //! Сложность сортировки `O(N·log(N))`.
//! \~\code //! \~\code
//! PIDeque<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3}; //! PIDeque<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
@@ -1507,7 +1507,7 @@ public:
//! \endcode //! \endcode
//! \~\sa \a sort(std::function<bool(const T &a, const T &b)> comp) //! \~\sa \a sort(std::function<bool(const T &a, const T &b)> comp)
inline PIDeque<T> & sort() { inline PIDeque<T> & sort() {
std::sort(begin(), end()); std::stable_sort(begin(), end());
return *this; return *this;
} }
@@ -1524,7 +1524,7 @@ public:
//! While the signature does not need to have const &, the function must not modify the objects passed to it. //! While the signature does not need to have const &, the function must not modify the objects passed to it.
//! The function must return `false` for identical elements, //! The function must return `false` for identical elements,
//! otherwise, it will lead to undefined program behavior and memory errors. //! otherwise, it will lead to undefined program behavior and memory errors.
//! Sorting provided by [std::sort](https://en.cppreference.com/w/cpp/algorithm/sort). //! Sorting provided by [std::stable_sort](https://en.cppreference.com/w/cpp/algorithm/stable_sort).
//! Complexity `O(N·log(N))`. //! Complexity `O(N·log(N))`.
//! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется. //! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется.
//! Для сравнения элементов используется функция сравнения `comp`. //! Для сравнения элементов используется функция сравнения `comp`.
@@ -1532,7 +1532,7 @@ public:
//! второго. Сигнатура функции сравнения должна быть эквивалентна следующей: \code bool comp(const T &a, const T &b); \endcode Сигнатура //! второго. Сигнатура функции сравнения должна быть эквивалентна следующей: \code bool comp(const T &a, const T &b); \endcode Сигнатура
//! не обязана содержать const &, однако, функция не может изменять переданные объекты. Функция обязана возвращать `false` для //! не обязана содержать const &, однако, функция не может изменять переданные объекты. Функция обязана возвращать `false` для
//! одинаковых элементов, иначе это приведёт к неопределённому поведению программы и ошибкам памяти. Для сортировки используется функция //! одинаковых элементов, иначе это приведёт к неопределённому поведению программы и ошибкам памяти. Для сортировки используется функция
//! [std::sort](https://ru.cppreference.com/w/cpp/algorithm/sort). Сложность сортировки `O(N·log(N))`. //! [std::stable_sort](https://ru.cppreference.com/w/cpp/algorithm/stable_sort). Сложность сортировки `O(N·log(N))`.
//! \~\code //! \~\code
//! PIDeque<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3}; //! PIDeque<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
//! v.sort([](const int & a, const int & b){return a > b;}); //! v.sort([](const int & a, const int & b){return a > b;});
@@ -1540,7 +1540,7 @@ public:
//! \endcode //! \endcode
//! \~\sa \a sort() //! \~\sa \a sort()
inline PIDeque<T> & sort(std::function<bool(const T & a, const T & b)> comp) { inline PIDeque<T> & sort(std::function<bool(const T & a, const T & b)> comp) {
std::sort(begin(), end(), comp); std::stable_sort(begin(), end(), comp);
return *this; return *this;
} }

View File

@@ -1420,11 +1420,11 @@ public:
//! \~\details //! \~\details
//! \~english The order of equal elements is not guaranteed to be preserved. //! \~english The order of equal elements is not guaranteed to be preserved.
//! Elements are compared using operator<. //! Elements are compared using operator<.
//! Sorting provided by [std::sort](https://en.cppreference.com/w/cpp/algorithm/sort). //! Sorting provided by [std::stable_sort](https://en.cppreference.com/w/cpp/algorithm/stable_sort).
//! Complexity `O(N·log(N))`. //! Complexity `O(N·log(N))`.
//! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется. //! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется.
//! Для сравнения элементов используется оператор `operator<`. //! Для сравнения элементов используется оператор `operator<`.
//! Для сортировки используется функция [std::sort](https://ru.cppreference.com/w/cpp/algorithm/sort). //! Для сортировки используется функция [std::stable_sort](https://ru.cppreference.com/w/cpp/algorithm/stable_sort).
//! Сложность сортировки `O(N·log(N))`. //! Сложность сортировки `O(N·log(N))`.
//! \~\code //! \~\code
//! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3}; //! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
@@ -1433,7 +1433,7 @@ public:
//! \endcode //! \endcode
//! \~\sa \a sort(std::function<bool(const T &a, const T &b)> comp) //! \~\sa \a sort(std::function<bool(const T &a, const T &b)> comp)
inline PIVector<T> & sort() { inline PIVector<T> & sort() {
std::sort(begin(), end()); std::stable_sort(begin(), end());
return *this; return *this;
} }
@@ -1450,7 +1450,7 @@ public:
//! While the signature does not need to have const &, the function must not modify the objects passed to it. //! While the signature does not need to have const &, the function must not modify the objects passed to it.
//! The function must return `false` for identical elements, //! The function must return `false` for identical elements,
//! otherwise, it will lead to undefined program behavior and memory errors. //! otherwise, it will lead to undefined program behavior and memory errors.
//! Sorting provided by [std::sort](https://en.cppreference.com/w/cpp/algorithm/sort). //! Sorting provided by [std::stable_sort](https://en.cppreference.com/w/cpp/algorithm/stable_sort).
//! Complexity `O(N·log(N))`. //! Complexity `O(N·log(N))`.
//! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется. //! \~russian Сохранность порядка элементов, имеющих одинаковое значение, не гарантируется.
//! Для сравнения элементов используется функция сравнения `comp`. //! Для сравнения элементов используется функция сравнения `comp`.
@@ -1458,7 +1458,7 @@ public:
//! второго. Сигнатура функции сравнения должна быть эквивалентна следующей: \code bool comp(const T &a, const T &b); \endcode Сигнатура //! второго. Сигнатура функции сравнения должна быть эквивалентна следующей: \code bool comp(const T &a, const T &b); \endcode Сигнатура
//! не обязана содержать const &, однако, функция не может изменять переданные объекты. Функция обязана возвращать `false` для //! не обязана содержать const &, однако, функция не может изменять переданные объекты. Функция обязана возвращать `false` для
//! одинаковых элементов, иначе это приведёт к неопределённому поведению программы и ошибкам памяти. Для сортировки используется функция //! одинаковых элементов, иначе это приведёт к неопределённому поведению программы и ошибкам памяти. Для сортировки используется функция
//! [std::sort](https://ru.cppreference.com/w/cpp/algorithm/sort). Сложность сортировки `O(N·log(N))`. //! [std::stable_sort](https://ru.cppreference.com/w/cpp/algorithm/stable_sort). Сложность сортировки `O(N·log(N))`.
//! \~\code //! \~\code
//! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3}; //! PIVector<int> v{5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
//! v.sort([](const int & a, const int & b){return a > b;}); //! v.sort([](const int & a, const int & b){return a > b;});
@@ -1466,7 +1466,7 @@ public:
//! \endcode //! \endcode
//! \~\sa \a sort() //! \~\sa \a sort()
inline PIVector<T> & sort(std::function<bool(const T & a, const T & b)> comp) { inline PIVector<T> & sort(std::function<bool(const T & a, const T & b)> comp) {
std::sort(begin(), end(), comp); std::stable_sort(begin(), end(), comp);
return *this; return *this;
} }

View File

@@ -536,7 +536,7 @@ PIString PIString::minArgPlaceholder() {
bool ok = false; bool ok = false;
tmp = mid(i + 1, j - i - 1); tmp = mid(i + 1, j - i - 1);
int cur = tmp.toInt(10, &ok); int cur = tmp.toInt(10, &ok);
if (!ok) continue; if (!ok || tmp.isEmpty()) continue;
if (min < 0 || min > cur) { if (min < 0 || min > cur) {
min = cur; min = cur;
ret = tmp; ret = tmp;