diff --git a/Convention/[Runtime]/Generics/Sequence.hpp b/Convention/[Runtime]/Generics/Sequence.hpp index 8ddb316..37fbfed 100644 --- a/Convention/[Runtime]/Generics/Sequence.hpp +++ b/Convention/[Runtime]/Generics/Sequence.hpp @@ -8,157 +8,15 @@ namespace Convention { namespace Generics { - namespace Iterator - { - - /** - * @brief 序列迭代器接口 - * @tparam ReadValueType 读出元素类型 - * @version BS 0.0.1 - */ - template - struct ISequenceIterator - { - virtual ~ISequenceIterator() {} - virtual void Next() abstract; - virtual ReadValueType ReadValue() const abstract; - ISequenceIterator& operator++() - { - this->Next(); - return *this; - } - virtual bool operator==(const ISequenceIterator& other) const noexcept abstract; - bool operator!=(const ISequenceIterator& other) const noexcept - { - return !(*this == other); - } - ReadValueType operator*() const - { - return ReadValue(); - } - }; - - /** - * @brief 序列迭代器的默认实现 - * @tparam Sequence 序列类型 - * @tparam Index 索引类型, 必须为具有operator++()的类型 - * @tparam ReadValueType 读出元素类型 - * @version BS 0.0.1 - */ - template< - typename Sequence, - typename Index, - typename ReadValueType = decltype(std::declval()[std::declval()]) - > - class DefaultSequenceIterator - : public ISequenceIterator, - public IComparable, ICompare> - { - private: - Sequence& target; - Index index; - public: - operator const Index&() - { - return index; - } - DefaultSequenceIterator(Sequence& target, Index index) - : __init(target), __init(index) - { - } - DefaultSequenceIterator(const DefaultSequenceIterator& other) noexcept - : target(other.target), index(other.index) - { - } - DefaultSequenceIterator& operator=(const DefaultSequenceIterator& other) noexcept - { - target = other.target; - index = other.index; - return *this; - } - virtual ~DefaultSequenceIterator() {} - void Next() - { - index++; - } - ReadValueType ReadValue() const - { - return target[index]; - } - bool operator==(const ISequenceIterator& other) const noexcept - { - auto ptr = dynamic_cast(&other); - if (ptr != nullptr) - return index == ptr->index; - return false; - } - }; - - } - - /** - * @brief 序列接口 - * @tparam Element 元素 - * @tparam Index 索引类型, 必须为具有operator++()的类型 - * @tparam ReadValueType 读出元素类型 - * @tparam SequenceIterator 迭代器类型 - * @version BS 0.0.1 - */ - template< - typename Element, - typename Index, - typename ReadValueType, - typename SequenceIterator - > - struct ISequence - { - virtual ~ISequence() {} - virtual ReadValueType operator[](Index index) abstract; - virtual SequenceIterator begin() abstract; - virtual SequenceIterator end() abstract; - }; /** * @brief 栈上静态数组 * @tparam Element 内容物类型 - * @tparam size 元素大小 + * @tparam ElementSize 内容物数量 * @version BS 0.0.1 */ - template - 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); - } - }; + template + using Array = std::array; /** * @brief 栈上静态Bool数组