BS 0.0.1 降低同化限制
This commit is contained in:
@@ -8,157 +8,15 @@ namespace Convention
|
|||||||
{
|
{
|
||||||
namespace Generics
|
namespace Generics
|
||||||
{
|
{
|
||||||
namespace Iterator
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 序列迭代器接口
|
|
||||||
* @tparam ReadValueType 读出元素类型
|
|
||||||
* @version BS 0.0.1
|
|
||||||
*/
|
|
||||||
template<typename ReadValueType>
|
|
||||||
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<Sequence>()[std::declval<Index>()])
|
|
||||||
>
|
|
||||||
class DefaultSequenceIterator
|
|
||||||
: public ISequenceIterator<ReadValueType>,
|
|
||||||
public IComparable<DefaultSequenceIterator<Sequence, Index, ReadValueType>, ICompare<Index>>
|
|
||||||
{
|
|
||||||
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<ReadValueType>& other) const noexcept
|
|
||||||
{
|
|
||||||
auto ptr = dynamic_cast<const DefaultSequenceIterator* const>(&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 栈上静态数组
|
* @brief 栈上静态数组
|
||||||
* @tparam Element 内容物类型
|
* @tparam Element 内容物类型
|
||||||
* @tparam size 元素大小
|
* @tparam ElementSize 内容物数量
|
||||||
* @version BS 0.0.1
|
* @version BS 0.0.1
|
||||||
*/
|
*/
|
||||||
template<typename Element, size_t size>
|
template<typename Element, size_t ElementSize>
|
||||||
class Array
|
using Array = std::array<Element, ElementSize>;
|
||||||
: 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