From ec561f517a120a077a1329b3d3a34208e4bc6070 Mon Sep 17 00:00:00 2001 From: ninemine <106434473+NINEMINEsigma@users.noreply.github.com> Date: Sat, 14 Jun 2025 12:56:47 +0800 Subject: [PATCH] BS 0.0.1 --- Convention/[Runtime]/Generics/Sequence.hpp | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/Convention/[Runtime]/Generics/Sequence.hpp b/Convention/[Runtime]/Generics/Sequence.hpp index 7c0fff3..8ddb316 100644 --- a/Convention/[Runtime]/Generics/Sequence.hpp +++ b/Convention/[Runtime]/Generics/Sequence.hpp @@ -101,20 +101,21 @@ namespace Convention * @tparam Element 元素 * @tparam Index 索引类型, 必须为具有operator++()的类型 * @tparam ReadValueType 读出元素类型 + * @tparam SequenceIterator 迭代器类型 * @version BS 0.0.1 */ template< typename Element, - typename Index = int, - typename ReadValueType = Element& + typename Index, + typename ReadValueType, + typename SequenceIterator > struct ISequence { virtual ~ISequence() {} virtual ReadValueType operator[](Index index) abstract; - virtual size_t size() const noexcept abstract; - Iterator::ISequenceIterator begin() abstract; - Iterator::ISequenceIterator end() abstract; + virtual SequenceIterator begin() abstract; + virtual SequenceIterator end() abstract; }; /** @@ -124,7 +125,40 @@ namespace Convention * @version BS 0.0.1 */ template - using Array = std::array; + class Array + : public ISequence, int64_t, Element&> + > + { + private: + std::array container; + public: + using iterator = Iterator::DefaultSequenceIterator, int64_t, Element&>; + template + Array(Args&&... args) :container(std::forward(args)...) {} + Array& operator=(Array&& other) + { + container = std::move(other.container); + return *this; + } + virtual ~Array() {} + decltype(auto) RawData() const noexcept + { + return container; + } + Element& operator[](int64_t index) override + { + return container[index < 0 ? index + size : index]; + } + virtual iterator begin() + { + return iterator(*this, 0); + } + virtual iterator end() + { + return iterator(*this, size); + } + }; /** * @brief 栈上静态Bool数组