Format like smack-a-brother, and write comments as sentences
Four-space indents, braces on their own lines, and one-statement bodies without braces. Semicolons in comments became full stops. Designated initializers may leave fields out without a warning.
This commit is contained in:
1 parent
40f6b554b5
commit
7afdf709c3
176 files changed
+20500
-19048
No files matched your search
+25
-18
@@ -5,42 +5,49 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
template <typename T> T* vector_find(std::vector<T>& v, int index)
|
||||
{
|
||||
template <typename T> T* vector_find(std::vector<T>& v, int index)
|
||||
{
|
||||
return index >= 0 && index < (int)v.size() ? &v[index] : nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> int vector_index_find(const std::vector<T>& v, const T& value)
|
||||
{
|
||||
template <typename T> int vector_index_find(const std::vector<T>& v, const T& value)
|
||||
{
|
||||
auto it = std::find(v.begin(), v.end(), value);
|
||||
if (it == v.end()) return -1;
|
||||
if (it == v.end())
|
||||
return -1;
|
||||
return (int)(std::distance(v.begin(), it));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> bool is_vector_in_bounds(std::vector<T>& v, int index) { return index >= 0 && index < (int)v.size(); }
|
||||
template <typename T> bool is_vector_in_bounds(std::vector<T>& v, int index)
|
||||
{
|
||||
return index >= 0 && index < (int)v.size();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::set<int> vector_indices_move(std::vector<T>& v, const std::vector<int>& indices, int insertPos)
|
||||
{
|
||||
if (indices.empty()) return {};
|
||||
template <typename T>
|
||||
std::set<int> vector_indices_move(std::vector<T>& v, const std::vector<int>& indices, int insertPos)
|
||||
{
|
||||
if (indices.empty())
|
||||
return {};
|
||||
|
||||
std::vector<int> sorted = indices;
|
||||
std::sort(sorted.begin(), sorted.end());
|
||||
sorted.erase(std::unique(sorted.begin(), sorted.end()), sorted.end());
|
||||
std::erase_if(sorted, [&](int i) { return i < 0 || i >= (int)v.size(); });
|
||||
if (sorted.empty()) return {};
|
||||
if (sorted.empty())
|
||||
return {};
|
||||
|
||||
std::vector<T> moveItems;
|
||||
moveItems.reserve(sorted.size());
|
||||
for (int i : sorted)
|
||||
moveItems.push_back(std::move(v[i]));
|
||||
moveItems.push_back(std::move(v[i]));
|
||||
|
||||
for (auto i : sorted | std::views::reverse)
|
||||
v.erase(v.begin() + i);
|
||||
v.erase(v.begin() + i);
|
||||
|
||||
insertPos = std::clamp(insertPos, 0, (int)v.size() + (int)sorted.size());
|
||||
for (int i : sorted)
|
||||
if (i < insertPos) --insertPos;
|
||||
if (i < insertPos)
|
||||
--insertPos;
|
||||
insertPos = std::clamp(insertPos, 0, (int)v.size());
|
||||
|
||||
v.insert(v.begin() + insertPos, std::make_move_iterator(moveItems.begin()),
|
||||
@@ -48,7 +55,7 @@
|
||||
|
||||
std::set<int> moveIndices;
|
||||
for (int i = 0; i < (int)moveItems.size(); i++)
|
||||
moveIndices.insert(insertPos + i);
|
||||
moveIndices.insert(insertPos + i);
|
||||
|
||||
return moveIndices;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user