BS 0.0.1
This commit is contained in:
@@ -101,20 +101,21 @@ namespace Convention
|
|||||||
* @tparam Element 元素
|
* @tparam Element 元素
|
||||||
* @tparam Index 索引类型, 必须为具有operator++()的类型
|
* @tparam Index 索引类型, 必须为具有operator++()的类型
|
||||||
* @tparam ReadValueType 读出元素类型
|
* @tparam ReadValueType 读出元素类型
|
||||||
|
* @tparam SequenceIterator 迭代器类型
|
||||||
* @version BS 0.0.1
|
* @version BS 0.0.1
|
||||||
*/
|
*/
|
||||||
template<
|
template<
|
||||||
typename Element,
|
typename Element,
|
||||||
typename Index = int,
|
typename Index,
|
||||||
typename ReadValueType = Element&
|
typename ReadValueType,
|
||||||
|
typename SequenceIterator
|
||||||
>
|
>
|
||||||
struct ISequence
|
struct ISequence
|
||||||
{
|
{
|
||||||
virtual ~ISequence() {}
|
virtual ~ISequence() {}
|
||||||
virtual ReadValueType operator[](Index index) abstract;
|
virtual ReadValueType operator[](Index index) abstract;
|
||||||
virtual size_t size() const noexcept abstract;
|
virtual SequenceIterator begin() abstract;
|
||||||
Iterator::ISequenceIterator<ReadValueType> begin() abstract;
|
virtual SequenceIterator end() abstract;
|
||||||
Iterator::ISequenceIterator<ReadValueType> end() abstract;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,7 +125,40 @@ namespace Convention
|
|||||||
* @version BS 0.0.1
|
* @version BS 0.0.1
|
||||||
*/
|
*/
|
||||||
template<typename Element, size_t size>
|
template<typename Element, size_t size>
|
||||||
using Array = std::array<Element, size>;
|
class Array
|
||||||
|
: public ISequence<Element, int64_t, Element&,
|
||||||
|
Iterator::DefaultSequenceIterator<Array<Element, size>, int64_t, Element&>
|
||||||
|
>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::array<Element, size> container;
|
||||||
|
public:
|
||||||
|
using iterator = Iterator::DefaultSequenceIterator<Array<Element, size>, int64_t, Element&>;
|
||||||
|
template<typename... Args>
|
||||||
|
Array(Args&&... args) :container(std::forward<Args>(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数组
|
* @brief 栈上静态Bool数组
|
||||||
|
Reference in New Issue
Block a user