flatten 20260225
This commit is contained in:
66
tjp/core/containers/FilledArray.hpp
Executable file
66
tjp/core/containers/FilledArray.hpp
Executable file
@@ -0,0 +1,66 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FilledArray.h"
|
||||
#include "StackArray.hpp"
|
||||
|
||||
#include "../debug/Debug.h"
|
||||
#include "../assert/debug_assert.h"
|
||||
#include <memory>
|
||||
#include <cstring> // memcpy
|
||||
#include "../threads/TestCollision.h"
|
||||
|
||||
namespace tjp {
|
||||
namespace core {
|
||||
|
||||
template<typename T, int N>
|
||||
struct FilledArray : StackArray<T, N>
|
||||
{
|
||||
using Super = StackArray<T, N>;
|
||||
using iterator = typename Super::iterator;
|
||||
using const_iterator = typename Super::const_iterator;
|
||||
|
||||
void insert(const T &element)
|
||||
{
|
||||
this->push_back(element);
|
||||
}
|
||||
|
||||
void erase (typename Super::iterator i)
|
||||
{
|
||||
if (i == this->end())
|
||||
return;
|
||||
|
||||
auto &back = this->back();
|
||||
if (i != &back)
|
||||
*i = std::move(back);
|
||||
|
||||
this->pop_back();
|
||||
}
|
||||
|
||||
void erase (const T &element)
|
||||
{
|
||||
erase(find(element));
|
||||
}
|
||||
|
||||
iterator find (const T &element)
|
||||
{
|
||||
// now iterator all except for what used to be the end element
|
||||
for (auto i=this->begin(); i!=this->end(); ++i)
|
||||
{
|
||||
if (*i == element)
|
||||
{
|
||||
// the end element was the last element
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return this->end();
|
||||
}
|
||||
} ;
|
||||
|
||||
} // namespace utilities
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user