[ox/std] Add Vector::at
All checks were successful
Build / build (push) Successful in 2m22s

This commit is contained in:
Gary Talent 2024-01-28 16:29:39 -06:00
parent f128664a81
commit 09c57545bc

View File

@ -221,6 +221,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
constexpr const T &operator[](std::size_t i) const noexcept;
[[nodiscard]]
constexpr Result<T*> at(size_t i) noexcept;
[[nodiscard]]
constexpr Result<T const*> at(size_t i) const noexcept;
[[nodiscard]]
constexpr Result<T*> front() noexcept;
@ -416,6 +422,22 @@ constexpr const T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t
return m_items[i];
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) noexcept {
if (i < size()) {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) const noexcept {
if (i < size()) {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
if (!m_size) {