Added IndexOf support for List.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -48,6 +48,16 @@ namespace Arbutils::Collections {
|
||||
return std::find(_vector.begin(), _vector.end(), value) != _vector.end();
|
||||
}
|
||||
|
||||
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
|
||||
/// \param value The value we want the index for.
|
||||
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
|
||||
inline size_t IndexOf(ValueT value) const {
|
||||
auto it = std::find(_vector.begin(), _vector.end(), value);
|
||||
if (it == _vector.end())
|
||||
return -1;
|
||||
return std::distance(_vector.begin(), it);
|
||||
}
|
||||
|
||||
inline void Append(ValueT value) { _vector.push_back(value); }
|
||||
|
||||
inline void Insert(size_t index, ValueT value) { _vector.insert(index, value); }
|
||||
@@ -59,9 +69,7 @@ namespace Arbutils::Collections {
|
||||
inline void Resize(size_t size) { _vector.resize(size); }
|
||||
inline void Resize(size_t size, ValueT defaultValue) { _vector.resize(size, defaultValue); }
|
||||
|
||||
inline void Remove(size_t index){
|
||||
_vector.erase(_vector.begin() + index);
|
||||
}
|
||||
inline void Remove(size_t index) { _vector.erase(_vector.begin() + index); }
|
||||
|
||||
iterator begin() { return _vector.begin(); }
|
||||
const_iterator begin() const { return _vector.begin(); }
|
||||
|
||||
Reference in New Issue
Block a user