From 163c8f75265054a168cc1e2750a0adb40fb08d83 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 22 Mar 2025 13:01:14 +0000 Subject: Make Collections::objects protected, extend interface Keeps all required features accessible, but through a controlled interface. --- lib/collection.h | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'lib/collection.h') diff --git a/lib/collection.h b/lib/collection.h index 2deefb9..c843bad 100644 --- a/lib/collection.h +++ b/lib/collection.h @@ -12,7 +12,19 @@ public: using Object = Ptr::element_type; using Objects = std::vector; - Objects objects; + + Collection & + operator=(Objects && other) + { + objects = std::move(other); + return *this; + } + + const Ptr & + operator[](size_t idx) const + { + return objects[idx]; + } template auto @@ -91,19 +103,45 @@ public: }); } - auto + [[nodiscard]] auto + begin() const + { + return objects.begin(); + } + + [[nodiscard]] auto end() const { return objects.end(); } - auto + [[nodiscard]] auto + rbegin() const + { + return objects.rbegin(); + } + + [[nodiscard]] auto rend() const { return objects.rend(); } + [[nodiscard]] bool + empty() const + { + return objects.empty(); + } + + auto + emplace(Ptr && ptr) + { + return objects.emplace_back(std::move(ptr)); + } + protected: + Objects objects; + template auto apply_internal(const auto begin, const auto end, const auto & m, Params &&... params) const -- cgit v1.2.3