mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 23:45:35 +08:00
28 lines
868 B
C++
28 lines
868 B
C++
// SPDX-FileCopyrightText: Copyright (C) 2021 swift Project Community / Contributors
|
|
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
|
|
|
|
//! \file
|
|
|
|
#include "misc/sequence.h"
|
|
|
|
#include <numeric>
|
|
|
|
namespace swift::misc::private_ns
|
|
{
|
|
QVector<int> findIndices(int size, const std::function<bool(int)> &predicate)
|
|
{
|
|
QVector<int> result(size);
|
|
std::iota(result.begin(), result.end(), 0);
|
|
result.erase(std::remove_if(result.begin(), result.end(), std::not_fn(predicate)), result.end());
|
|
return result;
|
|
}
|
|
|
|
QVector<int> sortIndices(int size, const std::function<bool(int, int)> &cmp)
|
|
{
|
|
QVector<int> result(size);
|
|
std::iota(result.begin(), result.end(), 0);
|
|
std::sort(result.begin(), result.end(), cmp);
|
|
return result;
|
|
}
|
|
} // namespace swift::misc::private_ns
|