From c033e7521f915804c457b68e93339d1444e7fcb5 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Fri, 16 Aug 2024 00:00:47 +0200 Subject: [PATCH] update concepts --- include/flatmemory/details/builder.hpp | 4 +- include/flatmemory/details/concepts.hpp | 8 +- .../details/containers/unordered_set.hpp | 35 ++- .../flatmemory/details/containers/vector.hpp | 85 ++++--- include/flatmemory/details/types/bitset.hpp | 211 ++++++++--------- include/flatmemory/details/types/tags.hpp | 110 --------- include/flatmemory/details/types/tuple.hpp | 125 +++++----- include/flatmemory/details/types/vector.hpp | 222 +++++++++--------- include/flatmemory/details/view.hpp | 4 +- include/flatmemory/details/view_const.hpp | 4 +- 10 files changed, 352 insertions(+), 456 deletions(-) delete mode 100644 include/flatmemory/details/types/tags.hpp diff --git a/include/flatmemory/details/builder.hpp b/include/flatmemory/details/builder.hpp index 0854fe0..d628a0e 100644 --- a/include/flatmemory/details/builder.hpp +++ b/include/flatmemory/details/builder.hpp @@ -72,13 +72,13 @@ class Builder : IBuilder> /** * Concepts */ -template> +template> struct maybe_builder { using type = T; }; -template +template struct maybe_builder { using type = Builder; diff --git a/include/flatmemory/details/concepts.hpp b/include/flatmemory/details/concepts.hpp index 0f6768d..2a8ee35 100644 --- a/include/flatmemory/details/concepts.hpp +++ b/include/flatmemory/details/concepts.hpp @@ -24,20 +24,20 @@ namespace flatmemory { /** - * Base ID class for custom types. + * Base ID class for non-trivial types. */ -struct Custom +struct NonTrivialType { }; template -concept IsCustom = std::derived_from; +concept IsNonTrivialType = std::derived_from; template concept IsTriviallyCopyable = std::is_trivially_copyable_v; template -concept IsTriviallyCopyableOrCustom = (IsTriviallyCopyable || IsCustom); +concept IsTriviallyCopyableOrNonTrivialType = (IsTriviallyCopyable || IsNonTrivialType); // Concept to check whether T is integral template diff --git a/include/flatmemory/details/containers/unordered_set.hpp b/include/flatmemory/details/containers/unordered_set.hpp index 980a2a6..e53a959 100644 --- a/include/flatmemory/details/containers/unordered_set.hpp +++ b/include/flatmemory/details/containers/unordered_set.hpp @@ -5,7 +5,6 @@ #include "flatmemory/details/builder.hpp" #include "flatmemory/details/byte_buffer_segmented.hpp" #include "flatmemory/details/concepts.hpp" -#include "flatmemory/details/types/tags.hpp" #include "flatmemory/details/view.hpp" #include "flatmemory/details/view_const.hpp" @@ -25,7 +24,7 @@ namespace flatmemory /// @tparam T /// @tparam Hash /// @tparam Equal -template>, typename Equal = std::equal_to>> +template>, typename Equal = std::equal_to>> class UnorderedSet { private: @@ -88,56 +87,56 @@ class UnorderedSet * Definitions */ -template +template UnorderedSet::UnorderedSet(NumBytes initial_num_bytes_per_segment, NumBytes maximum_num_bytes_per_segment) : m_storage(ByteBufferSegmented(initial_num_bytes_per_segment, maximum_num_bytes_per_segment)) { } -template +template UnorderedSet::iterator UnorderedSet::begin() { return m_data.begin(); } -template +template UnorderedSet::const_iterator UnorderedSet::begin() const { return m_data.begin(); } -template +template UnorderedSet::iterator UnorderedSet::end() { return m_data.end(); } -template +template UnorderedSet::const_iterator UnorderedSet::end() const { return m_data.end(); } -template +template bool UnorderedSet::empty() const { return m_data.empty(); } -template +template size_t UnorderedSet::size() const { return m_data.size(); } -template +template void UnorderedSet::clear() { m_storage.clear(); m_data.clear(); } -template +template std::pair::const_iterator, bool> UnorderedSet::insert(const Builder& builder) { const uint8_t* data = builder.buffer().data(); @@ -155,7 +154,7 @@ std::pair::const_iterator, bool> Unordered return std::make_pair(result.first, true); } -template +template std::pair::const_iterator, bool> UnorderedSet::insert(ConstView& view) { const uint8_t* data = view.buffer(); @@ -174,7 +173,7 @@ std::pair::const_iterator, bool> Unordered return std::make_pair(result.first, true); } -template +template std::pair::const_iterator, bool> UnorderedSet::insert(View& view) { const uint8_t* data = view.buffer(); @@ -192,31 +191,31 @@ std::pair::const_iterator, bool> Unordered return std::make_pair(result.first, true); } -template +template size_t UnorderedSet::count(ConstView key) const { return m_data.count(key); } -template +template UnorderedSet::iterator UnorderedSet::find(ConstView key) { return m_data.find(key); } -template +template UnorderedSet::const_iterator UnorderedSet::find(ConstView key) const { return m_data.find(key); } -template +template bool UnorderedSet::contains(ConstView key) const { return m_data.contains(key); } -template +template const ByteBufferSegmented& UnorderedSet::get_storage() const { return m_storage; diff --git a/include/flatmemory/details/containers/vector.hpp b/include/flatmemory/details/containers/vector.hpp index ac9d6ae..de559b8 100644 --- a/include/flatmemory/details/containers/vector.hpp +++ b/include/flatmemory/details/containers/vector.hpp @@ -5,7 +5,6 @@ #include "flatmemory/details/builder.hpp" #include "flatmemory/details/byte_buffer_segmented.hpp" #include "flatmemory/details/concepts.hpp" -#include "flatmemory/details/types/tags.hpp" #include "flatmemory/details/view.hpp" #include "flatmemory/details/view_const.hpp" @@ -24,7 +23,7 @@ namespace flatmemory /// but does not support resize since the exact /// amount of needed bytes is not known in advance. /// @tparam T -template +template class VariableSizedTypeVector { private: @@ -91,7 +90,7 @@ class VariableSizedTypeVector /// @brief FixedSizedTypeVector can handle only equally sized objects /// because it is meant to be resizeable. /// @tparam T -template +template class FixedSizedTypeVector { private: @@ -167,13 +166,13 @@ class FixedSizedTypeVector // VariableSizedTypeVector -template +template VariableSizedTypeVector::VariableSizedTypeVector(NumBytes initial_num_bytes_per_segment, NumBytes maximum_num_bytes_per_segment) : m_storage(ByteBufferSegmented(initial_num_bytes_per_segment, maximum_num_bytes_per_segment)) { } -template +template void VariableSizedTypeVector::range_check(size_t pos) const { if (pos >= size()) @@ -183,109 +182,109 @@ void VariableSizedTypeVector::range_check(size_t pos) const } } -template +template View VariableSizedTypeVector::operator[](size_t pos) { assert(pos <= size()); return m_data[pos]; } -template +template ConstView VariableSizedTypeVector::operator[](size_t pos) const { assert(pos <= size()); return m_data[pos]; } -template +template View VariableSizedTypeVector::at(size_t pos) { range_check(pos); return m_data[pos]; } -template +template ConstView VariableSizedTypeVector::at(size_t pos) const { range_check(pos); return m_data[pos]; } -template +template View VariableSizedTypeVector::back() { assert(!m_data.empty()); return m_data.back(); } -template +template ConstView VariableSizedTypeVector::back() const { assert(!m_data.empty()); return m_data.back(); } -template +template const ByteBufferSegmented& VariableSizedTypeVector::get_storage() const { return m_storage; } -template +template VariableSizedTypeVector::iterator VariableSizedTypeVector::begin() { return m_data.begin(); } -template +template VariableSizedTypeVector::const_iterator VariableSizedTypeVector::begin() const { return m_data.begin(); } -template +template VariableSizedTypeVector::iterator VariableSizedTypeVector::end() { return m_data.end(); } -template +template VariableSizedTypeVector::const_iterator VariableSizedTypeVector::end() const { return m_data.end(); } -template +template constexpr size_t VariableSizedTypeVector::empty() const { return m_data.empty(); } -template +template constexpr size_t VariableSizedTypeVector::size() const { return m_data.size(); } -template +template void VariableSizedTypeVector::push_back(const Builder& builder) { m_data.push_back(View(m_storage.write(builder.buffer().data(), builder.buffer().size()))); } -template +template void VariableSizedTypeVector::push_back(const View& view) { m_data.push_back(View(m_storage.write(view.buffer(), view.buffer_size()))); } -template +template void VariableSizedTypeVector::push_back(const ConstView& view) { m_data.push_back(View(m_storage.write(view.buffer(), view.buffer_size()))); } -template +template void VariableSizedTypeVector::clear() { m_data.clear(); @@ -294,14 +293,14 @@ void VariableSizedTypeVector::clear() // FixedSizedTypeVector -template +template FixedSizedTypeVector::FixedSizedTypeVector(NumBytes initial_num_bytes_per_segment, NumBytes maximum_num_bytes_per_segment) : m_storage(ByteBufferSegmented(initial_num_bytes_per_segment, maximum_num_bytes_per_segment)) { // m_default_builder.finish(); } -template +template FixedSizedTypeVector::FixedSizedTypeVector(Builder default_builder, NumBytes initial_num_bytes_per_segment, NumBytes maximum_num_bytes_per_segment) : m_storage(ByteBufferSegmented(initial_num_bytes_per_segment, maximum_num_bytes_per_segment)), m_default_builder(std::move(default_builder)) @@ -312,7 +311,7 @@ FixedSizedTypeVector::FixedSizedTypeVector(Builder default_builder, NumByt } } -template +template void FixedSizedTypeVector::range_check(size_t pos) const { if (pos >= size()) @@ -322,7 +321,7 @@ void FixedSizedTypeVector::range_check(size_t pos) const } } -template +template View FixedSizedTypeVector::operator[](size_t pos) { if (pos >= size()) @@ -332,14 +331,14 @@ View FixedSizedTypeVector::operator[](size_t pos) return m_data[pos]; } -template +template ConstView FixedSizedTypeVector::operator[](size_t pos) const { range_check(pos); return m_data[pos]; } -template +template View FixedSizedTypeVector::at(size_t pos) { if (pos >= size()) @@ -349,86 +348,86 @@ View FixedSizedTypeVector::at(size_t pos) return m_data[pos]; } -template +template ConstView FixedSizedTypeVector::at(size_t pos) const { range_check(pos); return m_data[pos]; } -template +template View FixedSizedTypeVector::back() { return m_data.back(); } -template +template ConstView FixedSizedTypeVector::back() const { return m_data.back(); } -template +template const ByteBufferSegmented& FixedSizedTypeVector::get_storage() const { return m_storage; } -template +template FixedSizedTypeVector::iterator FixedSizedTypeVector::begin() { return m_data.begin(); } -template +template FixedSizedTypeVector::const_iterator FixedSizedTypeVector::begin() const { return m_data.begin(); } -template +template FixedSizedTypeVector::iterator FixedSizedTypeVector::end() { return m_data.end(); } -template +template FixedSizedTypeVector::const_iterator FixedSizedTypeVector::end() const { return m_data.end(); } -template +template constexpr size_t FixedSizedTypeVector::empty() const { return m_data.empty(); } -template +template constexpr size_t FixedSizedTypeVector::size() const { return m_data.size(); } -template +template void FixedSizedTypeVector::push_back(const Builder& builder) { m_data.push_back(View(m_storage.write(builder.buffer().data(), builder.buffer().size()))); } -template +template void FixedSizedTypeVector::push_back(const View& view) { m_data.push_back(View(m_storage.write(view.buffer(), view.buffer_size()))); } -template +template void FixedSizedTypeVector::push_back(const ConstView& view) { m_data.push_back(View(m_storage.write(view.buffer(), view.buffer_size()))); } -template +template void FixedSizedTypeVector::resize(size_t count) { if (count < size()) @@ -444,7 +443,7 @@ void FixedSizedTypeVector::resize(size_t count) } } -template +template void FixedSizedTypeVector::clear() { m_data.clear(); diff --git a/include/flatmemory/details/types/bitset.hpp b/include/flatmemory/details/types/bitset.hpp index c50d341..e8396e9 100644 --- a/include/flatmemory/details/types/bitset.hpp +++ b/include/flatmemory/details/types/bitset.hpp @@ -29,7 +29,6 @@ #include "flatmemory/details/types/vector.hpp" #include "flatmemory/details/view.hpp" #include "flatmemory/details/view_const.hpp" -#include "flatmemory/details/types/tags.hpp" #include #include @@ -39,6 +38,19 @@ namespace flatmemory { +/** + * ID class for non-trivial Bitset type. + * The optional tag can be used to disallow operations with bitsets with other non-default tags. + */ + +template +struct Bitset : public NonTrivialType +{ + /// @brief Non-trivial copy-constructor + /// @param other + Bitset(const Bitset& other) {} +}; + /** * Layout */ @@ -101,7 +113,8 @@ concept HasCompatibleTagType = std::is_same_v || std:: /// @brief Concept for user define bitsets based on the STL template -concept IsUserDefinedBitset = requires(T a, const T b) { +concept IsUserDefinedBitset = requires(T a, const T b) +{ /* Common */ requires IsIntegral; @@ -110,24 +123,25 @@ concept IsUserDefinedBitset = requires(T a, const T b) { { a.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { a.get_blocks() - } -> std::same_as&>; + } -> std::same_as&>; /* Const version */ { b.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { b.get_blocks() - } -> std::same_as&>; + } -> std::same_as&>; }; /// @brief Concept for Builder template -concept IsBitsetBuilder = requires(T a, const T b) { +concept IsBitsetBuilder = requires(T a, const T b) +{ /* Common */ requires IsIntegral; @@ -137,24 +151,25 @@ concept IsBitsetBuilder = requires(T a, const T b) { { a.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { a.get_blocks() - } -> std::same_as>&>; + } -> std::same_as>&>; /* Const version */ { b.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { b.get_blocks() - } -> std::same_as>&>; + } -> std::same_as>&>; }; /// @brief Concept for View template -concept IsBitsetView = requires(T a, const T b) { +concept IsBitsetView = requires(T a, const T b) +{ /* Common */ requires IsIntegral; @@ -164,24 +179,25 @@ concept IsBitsetView = requires(T a, const T b) { { a.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { a.get_blocks() - } -> std::same_as>>; + } -> std::same_as>>; /* Const version */ { b.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { b.get_blocks() - } -> std::same_as>>; + } -> std::same_as>>; }; /// @brief Concept for ConstView template -concept IsBitsetConstView = requires(T a, const T b) { +concept IsBitsetConstView = requires(T a, const T b) +{ /* Common */ requires IsIntegral; @@ -191,19 +207,19 @@ concept IsBitsetConstView = requires(T a, const T b) { { a.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { a.get_blocks() - } -> std::same_as>>; + } -> std::same_as>>; /* Const version */ { b.get_default_bit_value() - } -> std::same_as; + } -> std::same_as; { b.get_blocks() - } -> std::same_as>>; + } -> std::same_as>>; }; /// @brief Concept for Bitset @@ -233,19 +249,19 @@ class Operator> * Operators */ template - requires HaveSameBlockType && HaveCompatibleTagType + requires HaveSameBlockType && HaveCompatibleTagType static bool are_equal(const L& left_bitset, const R& right_bitset); template - requires HaveSameBlockType && HaveCompatibleTagType + requires HaveSameBlockType && HaveCompatibleTagType static bool less(const L& left_bitset, const R& right_bitset); template - requires HaveSameBlockType && HaveCompatibleTagType + requires HaveSameBlockType && HaveCompatibleTagType static bool is_superseteq(const L& left_bitset, const R& right_bitset); template - requires HaveSameBlockType && HaveCompatibleTagType + requires HaveSameBlockType && HaveCompatibleTagType static bool are_disjoint(const L& left_bitset, const R& right_bitset); /** @@ -359,19 +375,19 @@ class View> */ template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator==(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator!=(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool is_superseteq(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool are_disjoint(const Other& other) const; /** @@ -454,19 +470,19 @@ class ConstView> */ template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator==(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator!=(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool is_superseteq(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool are_disjoint(const Other& other) const; /** @@ -542,11 +558,11 @@ class Builder> : public IBuilder>> const auto& get_buffer_impl() const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType void resize_to_fit(const Other& other); template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType void init_from_view(const Other& other); public: @@ -582,23 +598,23 @@ class Builder> : public IBuilder>> */ template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator<(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator==(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool operator!=(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool is_superseteq(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType + requires HasBlockType && HasCompatibleTagType bool are_disjoint(const Other& other) const; /** @@ -620,28 +636,22 @@ class Builder> : public IBuilder>> Builder& operator~(); template - requires HasBlockType && HasCompatibleTagType - Builder operator|(const Other& other) const; + requires HasBlockType && HasCompatibleTagType Builder operator|(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType - Builder& operator|=(const Other& other); + requires HasBlockType && HasCompatibleTagType Builder& operator|=(const Other& other); template - requires HasBlockType && HasCompatibleTagType - Builder operator&(const Other& other) const; + requires HasBlockType && HasCompatibleTagType Builder operator&(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType - Builder& operator&=(const Other& other); + requires HasBlockType && HasCompatibleTagType Builder& operator&=(const Other& other); template - requires HasBlockType && HasCompatibleTagType - Builder operator-(const Other& other) const; + requires HasBlockType && HasCompatibleTagType Builder operator-(const Other& other) const; template - requires HasBlockType && HasCompatibleTagType - Builder& operator-=(const Other& other); + requires HasBlockType && HasCompatibleTagType Builder& operator-=(const Other& other); /** * Lookup @@ -702,7 +712,7 @@ void Layout>::print() const template template - requires HaveSameBlockType && HaveCompatibleTagType +requires HaveSameBlockType && HaveCompatibleTagType bool Operator>::are_equal(const L& left_bitset, const R& right_bitset) { // Fetch data @@ -733,7 +743,7 @@ bool Operator>::are_equal(const L& left_bitset, const R& righ template template - requires HaveSameBlockType && HaveCompatibleTagType +requires HaveSameBlockType && HaveCompatibleTagType bool Operator>::less(const L& left_bitset, const R& right_bitset) { // Fetch data @@ -770,7 +780,7 @@ bool Operator>::less(const L& left_bitset, const R& right_bit template template - requires HaveSameBlockType && HaveCompatibleTagType +requires HaveSameBlockType && HaveCompatibleTagType bool Operator>::is_superseteq(const L& left_bitset, const R& right_bitset) { // Fetch data @@ -822,7 +832,7 @@ bool Operator>::is_superseteq(const L& left_bitset, const R& template template - requires HaveSameBlockType && HaveCompatibleTagType +requires HaveSameBlockType && HaveCompatibleTagType bool Operator>::are_disjoint(const L& left_bitset, const R& right_bitset) { // Fetch data @@ -1087,7 +1097,7 @@ View>::View(uint8_t* buf) : m_buf(buf) template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool View>::operator==(const Other& other) const { assert(m_buf); @@ -1096,15 +1106,12 @@ bool View>::operator==(const Other& other) const template template - requires HasBlockType && HasCompatibleTagType -bool View>::operator!=(const Other& other) const -{ - return !(*this == other); -} +requires HasBlockType && HasCompatibleTagType +bool View>::operator!=(const Other& other) const { return !(*this == other); } template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool View>::is_superseteq(const Other& other) const { assert(m_buf); @@ -1113,7 +1120,7 @@ bool View>::is_superseteq(const Other& other) const template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool View>::are_disjoint(const Other& other) const { assert(m_buf); @@ -1230,7 +1237,7 @@ ConstView>::ConstView(const BitsetView& view) : m_buf(view.bu template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool ConstView>::operator==(const Other& other) const { assert(m_buf); @@ -1239,15 +1246,12 @@ bool ConstView>::operator==(const Other& other) const template template - requires HasBlockType && HasCompatibleTagType -bool ConstView>::operator!=(const Other& other) const -{ - return !(*this == other); -} +requires HasBlockType && HasCompatibleTagType +bool ConstView>::operator!=(const Other& other) const { return !(*this == other); } template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool ConstView>::is_superseteq(const Other& other) const { assert(m_buf); @@ -1256,7 +1260,7 @@ bool ConstView>::is_superseteq(const Other& other) const template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType bool ConstView>::are_disjoint(const Other& other) const { assert(m_buf); @@ -1396,7 +1400,7 @@ const auto& Builder>::get_buffer_impl() const template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType void Builder>::resize_to_fit(const Other& other) { if (m_blocks.size() < other.get_blocks().size()) @@ -1409,7 +1413,7 @@ void Builder>::resize_to_fit(const Other& other) template template - requires HasBlockType && HasCompatibleTagType +requires HasBlockType && HasCompatibleTagType void Builder>::init_from_view(const Other& other) { m_default_bit_value = other.get_default_bit_value(); @@ -1468,43 +1472,28 @@ Builder>& Builder>::operator=(const Bitset template template - requires HasBlockType && HasCompatibleTagType -bool Builder>::operator<(const Other& other) const -{ - return BitsetOperator::less(*this, other); -} +requires HasBlockType && HasCompatibleTagType +bool Builder>::operator<(const Other& other) const { return BitsetOperator::less(*this, other); } template template - requires HasBlockType && HasCompatibleTagType -bool Builder>::operator==(const Other& other) const -{ - return BitsetOperator::are_equal(*this, other); -} +requires HasBlockType && HasCompatibleTagType +bool Builder>::operator==(const Other& other) const { return BitsetOperator::are_equal(*this, other); } template template - requires HasBlockType && HasCompatibleTagType -bool Builder>::operator!=(const Other& other) const -{ - return !(*this == other); -} +requires HasBlockType && HasCompatibleTagType +bool Builder>::operator!=(const Other& other) const { return !(*this == other); } template template - requires HasBlockType && HasCompatibleTagType -bool Builder>::is_superseteq(const Other& other) const -{ - return BitsetOperator::is_superseteq(*this, other); -} +requires HasBlockType && HasCompatibleTagType +bool Builder>::is_superseteq(const Other& other) const { return BitsetOperator::is_superseteq(*this, other); } template template - requires HasBlockType && HasCompatibleTagType -bool Builder>::are_disjoint(const Other& other) const -{ - return BitsetOperator::are_disjoint(*this, other); -} +requires HasBlockType && HasCompatibleTagType +bool Builder>::are_disjoint(const Other& other) const { return BitsetOperator::are_disjoint(*this, other); } template void Builder>::shrink_to_fit() @@ -1577,8 +1566,8 @@ Builder>& Builder>::operator~() template template - requires HasBlockType && HasCompatibleTagType -Builder> Builder>::operator|(const Other& other) const +requires HasBlockType && HasCompatibleTagType Builder> +Builder>::operator|(const Other& other) const { auto result = Builder>(*this); result |= other; @@ -1588,8 +1577,8 @@ Builder> Builder>::operator|(const Other& template template - requires HasBlockType && HasCompatibleTagType -Builder>& Builder>::operator|=(const Other& other) +requires HasBlockType && HasCompatibleTagType Builder> +&Builder>::operator|=(const Other& other) { // Fetch data const auto& other_blocks = other.get_blocks(); @@ -1618,8 +1607,8 @@ Builder>& Builder>::operator|=(const Other template template - requires HasBlockType && HasCompatibleTagType -Builder> Builder>::operator&(const Other& other) const +requires HasBlockType && HasCompatibleTagType Builder> +Builder>::operator&(const Other& other) const { auto result = Builder>(*this); result &= other; @@ -1629,8 +1618,8 @@ Builder> Builder>::operator&(const Other& template template - requires HasBlockType && HasCompatibleTagType -Builder>& Builder>::operator&=(const Other& other) +requires HasBlockType && HasCompatibleTagType Builder> +&Builder>::operator&=(const Other& other) { // Fetch data const auto& other_blocks = other.get_blocks(); @@ -1660,8 +1649,8 @@ Builder>& Builder>::operator&=(const Other template template - requires HasBlockType && HasCompatibleTagType -Builder> Builder>::operator-(const Other& other) const +requires HasBlockType && HasCompatibleTagType Builder> +Builder>::operator-(const Other& other) const { auto result = Builder>(*this); result -= other; @@ -1671,8 +1660,8 @@ Builder> Builder>::operator-(const Other& template template - requires HasBlockType && HasCompatibleTagType -Builder>& Builder>::operator-=(const Other& other) +requires HasBlockType && HasCompatibleTagType Builder> +&Builder>::operator-=(const Other& other) { // Fetch data const auto& other_blocks = other.get_blocks(); diff --git a/include/flatmemory/details/types/tags.hpp b/include/flatmemory/details/types/tags.hpp deleted file mode 100644 index 4386116..0000000 --- a/include/flatmemory/details/types/tags.hpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2024 Dominik Drexler - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef FLATMEMORY_TYPES_TAGS_HPP_ -#define FLATMEMORY_TYPES_TAGS_HPP_ - -#include "flatmemory/details/concepts.hpp" - -#include -#include - -namespace flatmemory -{ -/** - * Dispatcher for Bitset. - * The optional tag can be used to disallow operations between bitsets have similar tag. - */ - -template -struct Bitset : public Custom -{ - /// @brief Non-trivial copy-constructor - /// @param other - Bitset(const Bitset& other) {} -}; - -// Primary template for is_bitset_tag_helper -template -struct is_bitset_tag_helper : std::false_type -{ -}; - -// Specialization for Bitset -template -struct is_bitset_tag_helper> : std::true_type -{ -}; - -// Concept to check if a type is a Bitset -template -concept IsBitsetTag = is_bitset_tag_helper::value; - -/** - * Dispatcher for Tuple. - */ -template -struct Tuple : public Custom -{ - /// @brief Non-trivial copy-constructor - /// @param other - Tuple(const Tuple& other) {} -}; - -template -struct is_tuple_tag_helper : std::false_type -{ -}; - -template -struct is_tuple_tag_helper> : std::true_type -{ -}; - -template -concept IsTupleTag = is_tuple_tag_helper::value; - -/** - * Dispatcher for Vector. - */ -template -struct Vector : public Custom -{ - /// @brief Non-trivial copy-constructor - /// @param other - Vector(const Vector& other) {} -}; - -template -struct is_vector_tag_helper : std::false_type -{ -}; - -template -struct is_vector_tag_helper> : std::true_type -{ -}; - -template -concept IsVectorTag = is_vector_tag_helper::value; - -template -concept IsTag = IsBitsetTag || IsTupleTag || IsVectorTag; - -} - -#endif diff --git a/include/flatmemory/details/types/tuple.hpp b/include/flatmemory/details/types/tuple.hpp index 110c92b..252859d 100644 --- a/include/flatmemory/details/types/tuple.hpp +++ b/include/flatmemory/details/types/tuple.hpp @@ -27,7 +27,6 @@ #include "flatmemory/details/layout_utils.hpp" #include "flatmemory/details/view.hpp" #include "flatmemory/details/view_const.hpp" -#include "flatmemory/details/types/tags.hpp" #include #include @@ -40,11 +39,21 @@ namespace flatmemory { +/** + * ID class for non-trivial Tuple type. + */ +template +struct Tuple : public NonTrivialType +{ + /// @brief Non-trivial copy-constructor + /// @param other + Tuple(const Tuple& other) {} +}; /** * Layout */ -template +template class Layout> { private: @@ -103,7 +112,7 @@ class Layout> /** * Builder */ -template +template class Builder> : public IBuilder>> { public: @@ -170,7 +179,7 @@ class Builder> : public IBuilder>> /** * View */ -template +template class View> { public: @@ -245,7 +254,7 @@ class View> /** * ConstView */ -template +template class ConstView> { public: @@ -325,7 +334,7 @@ class ConstView> // Layout -template +template template consteval std::array Layout>::calculate_header_alignments(std::index_sequence) { @@ -341,7 +350,7 @@ consteval std::array Layout>::calculate_ return alignments; } -template +template template consteval std::array Layout>::calculate_data_alignments(std::index_sequence) { @@ -357,7 +366,7 @@ consteval std::array Layout>::calculate_ return alignments; } -template +template template consteval size_t Layout>::calculate_header_offset_type_size() { @@ -372,13 +381,13 @@ consteval size_t Layout>::calculate_header_offset_type_size() } } -template +template void Layout>::ElementData::print() const { std::cout << "position: " << position << " end: " << end << " padding: " << padding << std::endl; } -template +template void Layout>::LayoutData::print() const { std::cout << "buffer_size_position: " << buffer_size_position << "\n" @@ -391,7 +400,7 @@ void Layout>::LayoutData::print() const } } -template +template template consteval Layout>::LayoutData Layout>::calculate_layout_data(std::index_sequence index_sequence) { @@ -423,7 +432,7 @@ consteval Layout>::LayoutData Layout>::calculate_layou return LayoutData { buffer_size_position, buffer_size_end, buffer_size_padding, element_datas_position, element_datas }; } -template +template void Layout>::print() const { layout_data.print(); @@ -432,7 +441,7 @@ void Layout>::print() const // Builder -template +template template size_t Builder>::finish_iterative_impl(std::index_sequence, ByteBuffer& out, size_t pos) { @@ -470,31 +479,31 @@ size_t Builder>::finish_iterative_impl(std::index_sequence, return buffer_size; } -template +template void Builder>::finish_impl() { this->finish(m_buffer, 0); } -template +template size_t Builder>::finish_impl(ByteBuffer& out, size_t pos) { return finish_iterative_impl(std::make_index_sequence {}, out, pos); } -template +template auto& Builder>::get_buffer_impl() { return m_buffer; } -template +template const auto& Builder>::get_buffer_impl() const { return m_buffer; } -template +template bool Builder>::operator==(const Builder& other) const { if (this != &other) @@ -504,65 +513,65 @@ bool Builder>::operator==(const Builder& other) const return true; } -template +template template bool Builder>::compare_tuples(std::index_sequence, const ConstView>& other) const { return (... && (std::get(m_data) == other.template get())); } -template +template bool Builder>::operator==(const ConstView> other) const { // return compare_tuples(std::index_sequence_for {}, other); } -template +template template bool Builder>::compare_tuples(std::index_sequence, const View>& other) const { return (... && (std::get(m_data) == other.template get())); } -template +template bool Builder>::operator==(const View> other) const { // return compare_tuples(std::index_sequence_for {}, other); } -template +template bool Builder>::operator!=(const Builder& other) const { return !(*this == other); } -template +template bool Builder>::operator!=(const View>& other) const { return !(*this == other); } -template +template bool Builder>::operator!=(const ConstView>& other) const { return !(*this == other); } -template +template template auto& Builder>::get() { return std::get(m_data); } -template +template template const auto& Builder>::get() const { return std::get(m_data); } -template +template template size_t Builder>::hash_helper(std::index_sequence) const { @@ -584,7 +593,7 @@ size_t Builder>::hash_helper(std::index_sequence) const return seed; } -template +template size_t Builder>::hash() const { return hash_helper(std::make_index_sequence {}); @@ -592,26 +601,26 @@ size_t Builder>::hash() const // View -template +template View>::View(uint8_t* data) : m_buf(data) { assert(m_buf); } -template +template template bool View>::compare_tuples(std::index_sequence, const Builder>& other) const { return (... && (get() == other.template get())); } -template +template bool View>::operator==(const Builder> other) const { // return compare_tuples(std::index_sequence_for {}, other); } -template +template bool View>::operator==(const View& other) const { if (m_buf != other.buffer()) @@ -625,7 +634,7 @@ bool View>::operator==(const View& other) const return true; } -template +template bool View>::operator==(const ConstView> other) const { if (m_buf != other.buffer()) @@ -639,25 +648,25 @@ bool View>::operator==(const ConstView> other) const return true; } -template +template bool View>::operator!=(const Builder>& other) const { return !(*this == other); } -template +template bool View>::operator!=(const View>& other) const { return !(*this == other); } -template +template bool View>::operator!=(const ConstView>& other) const { return !(*this == other); } -template +template template decltype(auto) View>::get() { @@ -675,7 +684,7 @@ decltype(auto) View>::get() } } -template +template template decltype(auto) View>::get() const { @@ -693,18 +702,18 @@ decltype(auto) View>::get() const } } -template +template uint8_t* View>::buffer() { return m_buf; } -template +template const uint8_t* View>::buffer() const { return m_buf; } -template +template buffer_size_type View>::buffer_size() const { assert(m_buf); @@ -712,13 +721,13 @@ buffer_size_type View>::buffer_size() const return read_value(m_buf + Layout>::layout_data.buffer_size_position); } -template +template size_t View>::size() const { return Layout>::size; } -template +template size_t View>::hash() const { size_t seed = Layout>::size; @@ -729,31 +738,31 @@ size_t View>::hash() const // ConstView -template +template ConstView>::ConstView(const uint8_t* data) : m_buf(data) { assert(m_buf); } -template +template ConstView>::ConstView(const View>& view) : m_buf(view.buffer()) { } -template +template template bool ConstView>::compare_tuples(std::index_sequence, const Builder>& other) const { return (... && (get() == other.template get())); } -template +template bool ConstView>::operator==(const Builder> other) const { // return compare_tuples(std::index_sequence_for {}, other); } -template +template bool ConstView>::operator==(const View>& other) const { if (m_buf != other.buffer()) @@ -767,7 +776,7 @@ bool ConstView>::operator==(const View>& other) const return true; } -template +template bool ConstView>::operator==(const ConstView> other) const { if (m_buf != other.buffer()) @@ -781,25 +790,25 @@ bool ConstView>::operator==(const ConstView> other) co return true; } -template +template bool ConstView>::operator!=(const Builder>& other) const { return !(*this == other); } -template +template bool ConstView>::operator!=(const View>& other) const { return !(*this == other); } -template +template bool ConstView>::operator!=(const ConstView>& other) const { return !(*this == other); } -template +template template decltype(auto) ConstView>::get() const { @@ -817,7 +826,7 @@ decltype(auto) ConstView>::get() const } } -template +template buffer_size_type ConstView>::buffer_size() const { assert(m_buf); @@ -825,19 +834,19 @@ buffer_size_type ConstView>::buffer_size() const return read_value(m_buf + Layout>::layout_data.buffer_size_position); } -template +template const uint8_t* ConstView>::buffer() const { return m_buf; } -template +template size_t ConstView>::size() const { return Layout>::size; } -template +template size_t ConstView>::hash() const { size_t seed = Layout>::size; diff --git a/include/flatmemory/details/types/vector.hpp b/include/flatmemory/details/types/vector.hpp index c26b98e..913cb1e 100644 --- a/include/flatmemory/details/types/vector.hpp +++ b/include/flatmemory/details/types/vector.hpp @@ -29,7 +29,6 @@ #include "flatmemory/details/operator.hpp" #include "flatmemory/details/view.hpp" #include "flatmemory/details/view_const.hpp" -#include "flatmemory/details/types/tags.hpp" #include #include @@ -40,6 +39,17 @@ namespace flatmemory { +/** + * ID class for non-trivial Vector type. + */ +template +struct Vector : public NonTrivialType +{ + /// @brief Non-trivial copy-constructor + /// @param other + Vector(const Vector& other) {} +}; + /** * Data types */ @@ -48,19 +58,19 @@ using vector_size_type = uint32_t; /** * Forward declarations */ -template +template class View>; -template +template class ConstView>; -template +template class Builder>; /** * Operator */ -template +template class Operator> { private: @@ -70,7 +80,7 @@ class Operator> /** * Layout */ -template +template class Layout> { public: @@ -90,7 +100,7 @@ class Layout> /** * Builder */ -template +template class Builder> : public IBuilder>> { public: @@ -173,7 +183,7 @@ class Builder> : public IBuilder>> /** * View */ -template +template class View> { public: @@ -285,7 +295,7 @@ class View> /** * ConstView */ -template +template class ConstView> { public: @@ -382,7 +392,7 @@ class ConstView> // Layout -template +template void Layout>::print() const { std::cout << "buffer_size_position: " << buffer_size_position << "\n" @@ -397,13 +407,13 @@ void Layout>::print() const // Builder -template +template void Builder>::finish_impl() { this->finish(m_buffer, 0); } -template +template size_t Builder>::finish_impl(ByteBuffer& out, size_t pos) { /* Write header info */ @@ -452,34 +462,34 @@ size_t Builder>::finish_impl(ByteBuffer& out, size_t pos) return buffer_size; } -template +template auto& Builder>::get_buffer_impl() { return m_buffer; } -template +template const auto& Builder>::get_buffer_impl() const { return m_buffer; } -template +template Builder>::Builder() { } -template +template Builder>::Builder(size_t count) : m_data(count) { } -template +template Builder>::Builder(size_t count, const T_& value) : m_data(count, value) { } -template +template bool Builder>::operator==(const Builder& other) const { if (this != &other) @@ -489,7 +499,7 @@ bool Builder>::operator==(const Builder& other) const return true; } -template +template bool Builder>::operator==(const ConstView> other) const { if (size() != other.size()) @@ -509,7 +519,7 @@ bool Builder>::operator==(const ConstView> other) const return true; } -template +template bool Builder>::operator==(const View> other) const { if (size() != other.size()) @@ -529,39 +539,39 @@ bool Builder>::operator==(const View> other) const return true; } -template +template bool Builder>::operator!=(const Builder& other) const { return !(*this == other); } -template +template Builder>::T_& Builder>::operator[](size_t pos) { assert(pos < size()); return m_data[pos]; } -template +template const Builder>::T_& Builder>::operator[](size_t pos) const { assert(pos < size()); return m_data[pos]; } -template +template Builder>::T_& Builder>::at(size_t pos) { return m_data.at(pos); } -template +template const Builder>::T_& Builder>::at(size_t pos) const { return m_data.at(pos); } -template +template size_t Builder>::hash() const { constexpr bool is_trivial = IsTriviallyCopyable; @@ -580,79 +590,79 @@ size_t Builder>::hash() const } } -template +template Builder>::T_* Builder>::data() { return m_data.data(); } -template +template const Builder>::T_* Builder>::data() const { return m_data.data(); } -template +template Builder>::iterator Builder>::begin() { return m_data.begin(); } -template +template Builder>::const_iterator Builder>::begin() const { return m_data.begin(); } -template +template Builder>::iterator Builder>::end() { return m_data.end(); } -template +template Builder>::const_iterator Builder>::end() const { return m_data.end(); } -template +template constexpr bool Builder>::empty() const { return m_data.empty(); } -template +template constexpr size_t Builder>::size() const { return m_data.size(); } -template +template void Builder>::push_back(T_&& element) { m_data.push_back(std::move(element)); } -template +template void Builder>::push_back(const T_& element) { m_data.push_back(element); } -template +template void Builder>::resize(size_t count) { m_data.resize(count, T_()); } -template +template void Builder>::resize(size_t count, const T_& value) { m_data.resize(count, value); } -template +template void Builder>::clear() { m_data.clear(); @@ -660,13 +670,13 @@ void Builder>::clear() // View -template +template View>::View(uint8_t* buf) : m_buf(buf) { assert(m_buf); } -template +template void View>::range_check(size_t pos) const { if (pos >= size()) @@ -676,7 +686,7 @@ void View>::range_check(size_t pos) const } } -template +template bool View>::operator==(const Builder>& other) const { if (size() != other.size()) @@ -693,7 +703,7 @@ bool View>::operator==(const Builder>& other) const return true; } -template +template bool View>::operator==(const View>& other) const { if (m_buf != other.buffer()) @@ -707,7 +717,7 @@ bool View>::operator==(const View>& other) const return true; } -template +template bool View>::operator==(const ConstView>& other) const { if (m_buf != other.buffer()) @@ -721,25 +731,25 @@ bool View>::operator==(const ConstView>& other) const return true; } -template +template bool View>::operator!=(const Builder>& other) const { return !(*this == other); } -template +template bool View>::operator!=(const View>& other) const { return !(*this == other); } -template +template bool View>::operator!=(const ConstView>& other) const { return !(*this == other); } -template +template decltype(auto) View>::operator[](size_t pos) { assert(m_buf); @@ -757,7 +767,7 @@ decltype(auto) View>::operator[](size_t pos) } } -template +template decltype(auto) View>::operator[](size_t pos) const { assert(m_buf); @@ -775,21 +785,21 @@ decltype(auto) View>::operator[](size_t pos) const } } -template +template decltype(auto) View>::at(size_t pos) { range_check(pos); return (*this)[pos]; } -template +template decltype(auto) View>::at(size_t pos) const { range_check(pos); return (*this)[pos]; } -template +template size_t View>::hash() const { size_t seed = size(); @@ -798,40 +808,40 @@ size_t View>::hash() const return static_cast(hash[0] + 0x9e3779b9 + (hash[1] << 6) + (hash[1] >> 2)); } -template +template View>::T_* View>::data() { return reinterpret_cast>::T_*>(m_buf + Layout>::vector_data_position); } -template +template const View>::T_* View>::data() const { return reinterpret_cast>::T_*>(m_buf + Layout>::vector_data_position); } -template +template uint8_t* View>::buffer() { return m_buf; } -template +template const uint8_t* View>::buffer() const { return m_buf; } -template +template View>::iterator::iterator() : m_buf(nullptr) { } -template +template View>::iterator::iterator(uint8_t* buf) : m_buf(buf) { } -template +template decltype(auto) View>::iterator::operator*() const { constexpr bool is_trivial = IsTriviallyCopyable; @@ -846,7 +856,7 @@ decltype(auto) View>::iterator::operator*() const } } -template +template View>::iterator& View>::iterator::operator++() { constexpr bool is_trivial = IsTriviallyCopyable; @@ -861,7 +871,7 @@ View>::iterator& View>::iterator::operator++() return *this; } -template +template View>::iterator View>::iterator::operator++(int) { iterator tmp = *this; @@ -869,26 +879,26 @@ View>::iterator View>::iterator::operator++(int) return tmp; } -template +template bool View>::iterator::operator==(const View>::iterator& other) const { return m_buf == other.m_buf; } -template +template bool View>::iterator::operator!=(const View>::iterator& other) const { return !(*this == other); } -template +template View>::iterator View>::begin() { assert(m_buf); return View>::iterator(m_buf + Layout>::vector_data_position); } -template +template View>::iterator View>::end() { assert(m_buf); @@ -903,17 +913,17 @@ View>::iterator View>::end() } } -template +template View>::const_iterator::const_iterator() : m_buf(nullptr) { } -template +template View>::const_iterator::const_iterator(const uint8_t* buf) : m_buf(buf) { } -template +template decltype(auto) View>::const_iterator::operator*() const { constexpr bool is_trivial = IsTriviallyCopyable; @@ -928,7 +938,7 @@ decltype(auto) View>::const_iterator::operator*() const } } -template +template View>::const_iterator& View>::const_iterator::operator++() { constexpr bool is_trivial = IsTriviallyCopyable; @@ -943,7 +953,7 @@ View>::const_iterator& View>::const_iterator::operator++() return *this; } -template +template View>::const_iterator View>::const_iterator::operator++(int) { const_iterator tmp = *this; @@ -951,26 +961,26 @@ View>::const_iterator View>::const_iterator::operator++(int) return tmp; } -template +template bool View>::const_iterator::operator==(const View>::const_iterator& other) const { return m_buf == other.m_buf; } -template +template bool View>::const_iterator::operator!=(const View>::const_iterator& other) const { return !(*this == other); } -template +template View>::const_iterator View>::begin() const { assert(m_buf); return const_iterator(m_buf + Layout>::vector_data_position); } -template +template View>::const_iterator View>::end() const { assert(m_buf); @@ -985,13 +995,13 @@ View>::const_iterator View>::end() const } } -template +template bool View>::empty() const { return size() == 0; } -template +template buffer_size_type View>::buffer_size() const { assert(m_buf); @@ -999,7 +1009,7 @@ buffer_size_type View>::buffer_size() const return read_value(m_buf + Layout>::buffer_size_position); } -template +template size_t View>::size() const { assert(m_buf); @@ -1009,18 +1019,18 @@ size_t View>::size() const // ConstView -template +template ConstView>::ConstView(const uint8_t* buf) : m_buf(buf) { assert(buf); } -template +template ConstView>::ConstView(const View>& view) : m_buf(view.buffer()) { } -template +template void ConstView>::range_check(size_t pos) const { if (pos >= size()) @@ -1030,7 +1040,7 @@ void ConstView>::range_check(size_t pos) const } } -template +template bool ConstView>::operator==(const Builder>& other) const { if (size() != other.size()) @@ -1047,7 +1057,7 @@ bool ConstView>::operator==(const Builder>& other) const return true; } -template +template bool ConstView>::operator==(const ConstView>& other) const { if (m_buf != other.buffer()) @@ -1061,7 +1071,7 @@ bool ConstView>::operator==(const ConstView>& other) const return true; } -template +template bool ConstView>::operator==(const View>& other) const { if (m_buf != other.buffer()) @@ -1075,25 +1085,25 @@ bool ConstView>::operator==(const View>& other) const return true; } -template +template bool ConstView>::operator!=(const Builder>& other) const { return !(*this == other); } -template +template bool ConstView>::operator!=(const ConstView>& other) const { return !(*this == other); } -template +template bool ConstView>::operator!=(const View>& other) const { return !(*this == other); } -template +template decltype(auto) ConstView>::operator[](size_t pos) const { assert(m_buf); @@ -1111,14 +1121,14 @@ decltype(auto) ConstView>::operator[](size_t pos) const } } -template +template decltype(auto) ConstView>::at(size_t pos) const { range_check(pos); return (*this)[pos]; } -template +template size_t ConstView>::hash() const { size_t seed = size(); @@ -1127,29 +1137,29 @@ size_t ConstView>::hash() const return static_cast(hash[0] + 0x9e3779b9 + (hash[1] << 6) + (hash[1] >> 2)); } -template +template const ConstView>::T_* ConstView>::data() const { return reinterpret_cast>::T_*>(m_buf + Layout>::vector_data_position); } -template +template const uint8_t* ConstView>::buffer() const { return m_buf; } -template +template ConstView>::const_iterator::const_iterator() : m_buf(nullptr) { } -template +template ConstView>::const_iterator::const_iterator(const uint8_t* buf) : m_buf(buf) { } -template +template decltype(auto) ConstView>::const_iterator::operator*() const { constexpr bool is_trivial = IsTriviallyCopyable; @@ -1164,7 +1174,7 @@ decltype(auto) ConstView>::const_iterator::operator*() const } } -template +template ConstView>::const_iterator& ConstView>::const_iterator::operator++() { constexpr bool is_trivial = IsTriviallyCopyable; @@ -1179,7 +1189,7 @@ ConstView>::const_iterator& ConstView>::const_iterator::oper return *this; } -template +template ConstView>::const_iterator ConstView>::const_iterator::operator++(int) { const_iterator tmp = *this; @@ -1187,26 +1197,26 @@ ConstView>::const_iterator ConstView>::const_iterator::opera return tmp; } -template +template bool ConstView>::const_iterator::operator==(const ConstView>::const_iterator& other) const { return m_buf == other.m_buf; } -template +template bool ConstView>::const_iterator::operator!=(const ConstView>::const_iterator& other) const { return !(*this == other); } -template +template ConstView>::const_iterator ConstView>::begin() const { assert(m_buf); return const_iterator(m_buf + Layout>::vector_data_position); } -template +template ConstView>::const_iterator ConstView>::end() const { assert(m_buf); @@ -1221,13 +1231,13 @@ ConstView>::const_iterator ConstView>::end() const } } -template +template bool ConstView>::empty() const { return size() == 0; } -template +template buffer_size_type ConstView>::buffer_size() const { assert(m_buf); @@ -1235,7 +1245,7 @@ buffer_size_type ConstView>::buffer_size() const return read_value(m_buf + Layout>::buffer_size_position); } -template +template size_t ConstView>::size() const { assert(m_buf); @@ -1252,19 +1262,19 @@ static_assert(std::ranges::forward_range>>); static_assert(std::ranges::forward_range>>); } -template +template struct std::hash> { size_t operator()(const flatmemory::Builder>& vector) const { return vector.hash(); } }; -template +template struct std::hash>> { size_t operator()(const flatmemory::View>& vector) const { return vector.hash(); } }; -template +template struct std::hash>> { size_t operator()(const flatmemory::ConstView>& vector) const { return vector.hash(); } diff --git a/include/flatmemory/details/view.hpp b/include/flatmemory/details/view.hpp index 0401370..3dbd4a8 100644 --- a/include/flatmemory/details/view.hpp +++ b/include/flatmemory/details/view.hpp @@ -37,13 +37,13 @@ class View /** * Concepts */ -template> +template> struct maybe_view { using type = T; }; -template +template struct maybe_view { using type = View; diff --git a/include/flatmemory/details/view_const.hpp b/include/flatmemory/details/view_const.hpp index a9b541c..0ae457f 100644 --- a/include/flatmemory/details/view_const.hpp +++ b/include/flatmemory/details/view_const.hpp @@ -35,13 +35,13 @@ class ConstView /** * Concepts */ -template> +template> struct maybe_const_view { using type = T; }; -template +template struct maybe_const_view { using type = ConstView;