summaryrefslogtreecommitdiff
path: root/AK/NonnullPtrVector.h
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-08-24 10:48:44 +0100
committerAndreas Kling <kling@serenityos.org>2022-09-08 18:53:08 +0200
commitedc3ed2a0ed4060460d86a144efbdbdc3c237a2e (patch)
tree5e7abd8d41c7dca6f51d343a2a5c9aa817adffe6 /AK/NonnullPtrVector.h
parentf3877daac56c769eb4c9024ae538e61a69fce25c (diff)
downloadserenity-edc3ed2a0ed4060460d86a144efbdbdc3c237a2e.zip
AK: Allow creating NonnullPtrVectors from an initializer list
This was present in Vector already. Clang-format fixed some const positions automatically too. Also removed a now-ambiguous and unnecessary constructor from Shell.
Diffstat (limited to 'AK/NonnullPtrVector.h')
-rw-r--r--AK/NonnullPtrVector.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/AK/NonnullPtrVector.h b/AK/NonnullPtrVector.h
index 6471dd3586..d78dcfab7e 100644
--- a/AK/NonnullPtrVector.h
+++ b/AK/NonnullPtrVector.h
@@ -26,10 +26,14 @@ public:
: Base(static_cast<Base const&>(other))
{
}
+ NonnullPtrVector(std::initializer_list<PtrType> list)
+ : Base(list)
+ {
+ }
using Base::size;
- using ConstIterator = SimpleIterator<const NonnullPtrVector, const T>;
+ using ConstIterator = SimpleIterator<NonnullPtrVector const, T const>;
using Iterator = SimpleIterator<NonnullPtrVector, T>;
using ReverseIterator = SimpleReverseIterator<NonnullPtrVector, T>;
using ReverseConstIterator = SimpleReverseIterator<NonnullPtrVector const, T const>;
@@ -60,13 +64,13 @@ public:
ALWAYS_INLINE PtrType const& ptr_at(size_t index) const { return Base::at(index); }
ALWAYS_INLINE T& at(size_t index) { return *Base::at(index); }
- ALWAYS_INLINE const T& at(size_t index) const { return *Base::at(index); }
+ ALWAYS_INLINE T const& at(size_t index) const { return *Base::at(index); }
ALWAYS_INLINE T& operator[](size_t index) { return at(index); }
- ALWAYS_INLINE const T& operator[](size_t index) const { return at(index); }
+ ALWAYS_INLINE T const& operator[](size_t index) const { return at(index); }
ALWAYS_INLINE T& first() { return at(0); }
- ALWAYS_INLINE const T& first() const { return at(0); }
+ ALWAYS_INLINE T const& first() const { return at(0); }
ALWAYS_INLINE T& last() { return at(size() - 1); }
- ALWAYS_INLINE const T& last() const { return at(size() - 1); }
+ ALWAYS_INLINE T const& last() const { return at(size() - 1); }
private:
// NOTE: You can't use resize() on a NonnullFooPtrVector since making the vector