diff --git a/include/tsl/sparse_hash.h b/include/tsl/sparse_hash.h index 3547c24..504a4a4 100644 --- a/include/tsl/sparse_hash.h +++ b/include/tsl/sparse_hash.h @@ -993,7 +993,7 @@ class sparse_array { template + tsl::sh::probing Probing, class ValueTypeIt> class sparse_hash : private Allocator, private Hash, private KeyEqual, @@ -1027,6 +1027,12 @@ class sparse_hash : private Allocator, using iterator = sparse_iterator; using const_iterator = sparse_iterator; + using value_type_it = ValueTypeIt; + using reference_it = value_type_it &; + using const_reference_it = const value_type_it &; + using pointer_it = value_type_it *; + using const_pointer_it = const value_type_it *; + private: using sparse_array = tsl::detail_sparse_hash::sparse_array; @@ -1070,10 +1076,16 @@ class sparse_hash : private Allocator, public: using iterator_category = std::forward_iterator_tag; - using value_type = const typename sparse_hash::value_type; + using value_type = typename sparse_hash::value_type_it; using difference_type = std::ptrdiff_t; - using reference = value_type &; - using pointer = value_type *; + using reference = + typename std::conditional::type; + using pointer = + typename std::conditional::type; sparse_iterator() noexcept {} @@ -1107,9 +1119,13 @@ class sparse_hash : private Allocator, return U()(*m_sparse_array_it); } - reference operator*() const { return *m_sparse_array_it; } + reference operator*() const { + return reinterpret_cast(*m_sparse_array_it); + } - pointer operator->() const { return std::addressof(*m_sparse_array_it); } + pointer operator->() const { + return reinterpret_cast(std::addressof(*m_sparse_array_it)); + } sparse_iterator &operator++() { tsl_sh_assert(m_sparse_array_it != nullptr); diff --git a/include/tsl/sparse_map.h b/include/tsl/sparse_map.h index 601742d..1fbe622 100644 --- a/include/tsl/sparse_map.h +++ b/include/tsl/sparse_map.h @@ -103,6 +103,15 @@ class sparse_map { key_type &operator()(std::pair &key_value) noexcept { return key_value.first; } + + const key_type &operator()( + const std::pair &key_value) const noexcept { + return key_value.first; + } + + const key_type &operator()(std::pair &key_value) noexcept { + return key_value.first; + } }; class ValueSelect { @@ -121,7 +130,8 @@ class sparse_map { using ht = detail_sparse_hash::sparse_hash< std::pair, KeySelect, ValueSelect, Hash, KeyEqual, Allocator, - GrowthPolicy, ExceptionSafety, Sparsity, tsl::sh::probing::quadratic>; + GrowthPolicy, ExceptionSafety, Sparsity, tsl::sh::probing::quadratic, + std::pair>; public: using key_type = typename ht::key_type; diff --git a/include/tsl/sparse_set.h b/include/tsl/sparse_set.h index 3ce6a58..d313723 100644 --- a/include/tsl/sparse_set.h +++ b/include/tsl/sparse_set.h @@ -100,10 +100,9 @@ class sparse_set { key_type &operator()(Key &key) noexcept { return key; } }; - using ht = - detail_sparse_hash::sparse_hash; + using ht = detail_sparse_hash::sparse_hash< + Key, KeySelect, void, Hash, KeyEqual, Allocator, GrowthPolicy, + ExceptionSafety, Sparsity, tsl::sh::probing::quadratic, Key>; public: using key_type = typename ht::key_type;