Skip to content
Snippets Groups Projects
Commit cc4e2a69 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

OwningVector + fcts index_of, swap

parent a45caa59
No related branches found
No related tags found
1 merge request!2370cleanup and prepare refactoring in MasksSet context
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define BORNAGAIN_BASE_TYPES_OWNINGVECTOR_H #define BORNAGAIN_BASE_TYPES_OWNINGVECTOR_H
#include "Base/Util/Assert.h" #include "Base/Util/Assert.h"
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -58,6 +59,14 @@ public: ...@@ -58,6 +59,14 @@ public:
T* const& at(int i) const { return m_v.at(i); } T* const& at(int i) const { return m_v.at(i); }
T* const& front() const { return m_v.front(); } T* const& front() const { return m_v.front(); }
T* const& back() const { return m_v.back(); } T* const& back() const { return m_v.back(); }
int index_of(const T* t) const
{
for (size_t i = 0; i < m_v.size(); i++)
if (m_v[i] == t)
return int(i);
return -1;
}
void delete_element(T* e) void delete_element(T* e)
{ {
...@@ -113,7 +122,16 @@ public: ...@@ -113,7 +122,16 @@ public:
return result; return result;
} }
const std::vector<const T*>& reference() const { return m_v; } void swap(size_t fromIndex, size_t toIndex)
{
if (fromIndex > toIndex)
std::rotate(m_v.rend() - fromIndex - 1, m_v.rend() - fromIndex, m_v.rend() - toIndex);
else
std::rotate(m_v.begin() + fromIndex, m_v.begin() + fromIndex + 1,
m_v.begin() + toIndex + 1);
}
const std::vector<T*>& shared() const { return m_v; }
std::vector<const T*> const_vector() const std::vector<const T*> const_vector() const
{ {
const std::vector<const T*> result(m_v.begin(), m_v.end()); const std::vector<const T*> result(m_v.begin(), m_v.end());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment