Skip to content

Commit

Permalink
update concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Aug 15, 2024
1 parent 0ead962 commit c033e75
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 456 deletions.
4 changes: 2 additions & 2 deletions include/flatmemory/details/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class Builder : IBuilder<Builder<Tag>>
/**
* Concepts
*/
template<IsTriviallyCopyableOrCustom T, bool = IsTriviallyCopyable<T>>
template<IsTriviallyCopyableOrNonTrivialType T, bool = IsTriviallyCopyable<T>>
struct maybe_builder
{
using type = T;
};

template<IsTriviallyCopyableOrCustom T>
template<IsTriviallyCopyableOrNonTrivialType T>
struct maybe_builder<T, false>
{
using type = Builder<T>;
Expand Down
8 changes: 4 additions & 4 deletions include/flatmemory/details/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
namespace flatmemory
{
/**
* Base ID class for custom types.
* Base ID class for non-trivial types.
*/
struct Custom
struct NonTrivialType
{
};

template<typename T>
concept IsCustom = std::derived_from<T, Custom>;
concept IsNonTrivialType = std::derived_from<T, NonTrivialType>;

template<typename T>
concept IsTriviallyCopyable = std::is_trivially_copyable_v<T>;

template<typename T>
concept IsTriviallyCopyableOrCustom = (IsTriviallyCopyable<T> || IsCustom<T>);
concept IsTriviallyCopyableOrNonTrivialType = (IsTriviallyCopyable<T> || IsNonTrivialType<T>);

// Concept to check whether T is integral
template<typename T>
Expand Down
35 changes: 17 additions & 18 deletions include/flatmemory/details/containers/unordered_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -25,7 +24,7 @@ namespace flatmemory
/// @tparam T
/// @tparam Hash
/// @tparam Equal
template<IsTag T, typename Hash = std::hash<ConstView<T>>, typename Equal = std::equal_to<ConstView<T>>>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash = std::hash<ConstView<T>>, typename Equal = std::equal_to<ConstView<T>>>
class UnorderedSet
{
private:
Expand Down Expand Up @@ -88,56 +87,56 @@ class UnorderedSet
* Definitions
*/

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::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<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::iterator UnorderedSet<T, Hash, Equal>::begin()
{
return m_data.begin();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::const_iterator UnorderedSet<T, Hash, Equal>::begin() const
{
return m_data.begin();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::iterator UnorderedSet<T, Hash, Equal>::end()
{
return m_data.end();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::const_iterator UnorderedSet<T, Hash, Equal>::end() const
{
return m_data.end();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
bool UnorderedSet<T, Hash, Equal>::empty() const
{
return m_data.empty();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
size_t UnorderedSet<T, Hash, Equal>::size() const
{
return m_data.size();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
void UnorderedSet<T, Hash, Equal>::clear()
{
m_storage.clear();
m_data.clear();
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> UnorderedSet<T, Hash, Equal>::insert(const Builder<T>& builder)
{
const uint8_t* data = builder.buffer().data();
Expand All @@ -155,7 +154,7 @@ std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> Unordered
return std::make_pair(result.first, true);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> UnorderedSet<T, Hash, Equal>::insert(ConstView<T>& view)
{
const uint8_t* data = view.buffer();
Expand All @@ -174,7 +173,7 @@ std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> Unordered
return std::make_pair(result.first, true);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> UnorderedSet<T, Hash, Equal>::insert(View<T>& view)
{
const uint8_t* data = view.buffer();
Expand All @@ -192,31 +191,31 @@ std::pair<typename UnorderedSet<T, Hash, Equal>::const_iterator, bool> Unordered
return std::make_pair(result.first, true);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
size_t UnorderedSet<T, Hash, Equal>::count(ConstView<T> key) const
{
return m_data.count(key);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::iterator UnorderedSet<T, Hash, Equal>::find(ConstView<T> key)
{
return m_data.find(key);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
UnorderedSet<T, Hash, Equal>::const_iterator UnorderedSet<T, Hash, Equal>::find(ConstView<T> key) const
{
return m_data.find(key);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
bool UnorderedSet<T, Hash, Equal>::contains(ConstView<T> key) const
{
return m_data.contains(key);
}

template<IsTag T, typename Hash, typename Equal>
template<IsTriviallyCopyableOrNonTrivialType T, typename Hash, typename Equal>
const ByteBufferSegmented& UnorderedSet<T, Hash, Equal>::get_storage() const
{
return m_storage;
Expand Down
Loading

0 comments on commit c033e75

Please sign in to comment.