diff --git a/include/tsl/array_hash.h b/include/tsl/array_hash.h index c8eaf6c..eb36027 100644 --- a/include/tsl/array_hash.h +++ b/include/tsl/array_hash.h @@ -41,28 +41,26 @@ #include "array_growth_policy.h" +/* + * __has_include is a bit useless (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433), + * check also __cplusplus version. + */ #ifdef __has_include - /* - * __has_include is a bit useless (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79433), - * check also __cplusplus version. - */ - #if __has_include() && __cplusplus >= 201703L - #define TSL_HAS_STRING_VIEW - #endif +# if __has_include() && __cplusplus >= 201703L +# define TSL_AH_HAS_STRING_VIEW +# endif #endif -#ifdef TSL_HAS_STRING_VIEW -#include +#ifdef TSL_AH_HAS_STRING_VIEW +# include #endif -#ifndef tsl_assert - #ifdef TSL_DEBUG - #define tsl_assert(expr) assert(expr) - #else - #define tsl_assert(expr) (static_cast(0)) - #endif +#ifdef TSL_DEBUG +# define tsl_ah_assert(expr) assert(expr) +#else +# define tsl_ah_assert(expr) (static_cast(0)) #endif @@ -378,7 +376,7 @@ class array_bucket { const key_size_type key_sz = as_key_size_type(key_size); if(end_of_bucket == cend()) { - tsl_assert(m_buffer == nullptr); + tsl_ah_assert(m_buffer == nullptr); const size_type buffer_size = entry_required_bytes(key_sz) + sizeof_in_buff(); @@ -392,7 +390,7 @@ class array_bucket { return const_iterator(m_buffer); } else { - tsl_assert(is_end_of_bucket(end_of_bucket.m_position)); + tsl_ah_assert(is_end_of_bucket(end_of_bucket.m_position)); const size_type current_size = ((end_of_bucket.m_position + size_as_char_t()) - m_buffer) * sizeof(CharT); @@ -416,7 +414,7 @@ class array_bucket { } const_iterator erase(const_iterator position) noexcept { - tsl_assert(position.m_position != nullptr && !is_end_of_bucket(position.m_position)); + tsl_ah_assert(position.m_position != nullptr && !is_end_of_bucket(position.m_position)); // get mutable pointers CharT* start_entry = m_buffer + (position.m_position - m_buffer); @@ -715,7 +713,7 @@ class array_hash: private value_container, private Hash, private GrowthPolicy m_array_bucket_iterator(array_bucket_iterator), m_array_hash(array_hash_p) { - tsl_assert(m_array_hash != nullptr); + tsl_ah_assert(m_array_hash != nullptr); } public: @@ -737,7 +735,7 @@ class array_hash: private value_container, private Hash, private GrowthPolicy return m_array_bucket_iterator.key_size(); } -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::basic_string_view key_sv() const { return std::basic_string_view(key(), key_size()); } @@ -759,8 +757,8 @@ class array_hash: private value_container, private Hash, private GrowthPolicy } array_hash_iterator& operator++() { - tsl_assert(m_buckets_iterator != m_array_hash->m_buckets.end()); - tsl_assert(m_array_bucket_iterator != m_buckets_iterator->cend()); + tsl_ah_assert(m_buckets_iterator != m_array_hash->m_buckets.end()); + tsl_ah_assert(m_array_bucket_iterator != m_buckets_iterator->cend()); ++m_array_bucket_iterator; if(m_array_bucket_iterator == m_buckets_iterator->cend()) { @@ -1297,7 +1295,7 @@ class array_hash: private value_container, private Hash, private GrowthPolicy } new_values.swap(this->m_values); - tsl_assert(m_nb_elements == this->m_values.size()); + tsl_ah_assert(m_nb_elements == this->m_values.size()); } /** diff --git a/include/tsl/array_map.h b/include/tsl/array_map.h index 53e51a5..35f74d3 100644 --- a/include/tsl/array_map.h +++ b/include/tsl/array_map.h @@ -103,7 +103,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW array_map(std::initializer_list, T>> init, size_type bucket_count = ht::DEFAULT_INIT_BUCKET_COUNT, const Hash& hash = Hash()): array_map(bucket_count, hash) @@ -121,7 +121,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW array_map& operator=(std::initializer_list, T>> ilist) { clear(); @@ -174,7 +174,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::pair insert(const std::basic_string_view& key, const T& value) { return m_ht.emplace(key.data(), key.size(), value); } @@ -193,7 +193,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::pair insert(const std::basic_string_view& key, T&& value) { return m_ht.emplace(key.data(), key.size(), std::move(value)); } @@ -232,7 +232,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW void insert(std::initializer_list, T>> ilist) { insert(ilist.begin(), ilist.end()); } @@ -244,7 +244,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW template std::pair insert_or_assign(const std::basic_string_view& key, M&& obj) { return m_ht.insert_or_assign(key.data(), key.size(), std::forward(obj)); @@ -267,7 +267,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW template std::pair emplace(const std::basic_string_view& key, Args&&... args) { return m_ht.emplace(key.data(), key.size(), std::forward(args)...); @@ -308,7 +308,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc erase(const_iterator pos) */ @@ -339,7 +339,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc erase_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ @@ -380,7 +380,7 @@ class array_map { /* * Lookup */ -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW T& at(const std::basic_string_view& key) { return m_ht.at(key.data(), key.size()); } @@ -415,7 +415,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc at_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ @@ -475,7 +475,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW T& operator[](const std::basic_string_view& key) { return m_ht.access_operator(key.data(), key.size()); } #else T& operator[](const CharT* key) { return m_ht.access_operator(key, std::strlen(key)); } @@ -484,7 +484,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW size_type count(const std::basic_string_view& key) const { return m_ht.count(key.data(), key.size()); } @@ -503,7 +503,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc count_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) const */ @@ -535,7 +535,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW iterator find(const std::basic_string_view& key) { return m_ht.find(key.data(), key.size()); } @@ -570,7 +570,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc find_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ @@ -630,7 +630,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::pair equal_range(const std::basic_string_view& key) { return m_ht.equal_range(key.data(), key.size()); } @@ -665,7 +665,7 @@ class array_map { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc equal_range_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ diff --git a/include/tsl/array_set.h b/include/tsl/array_set.h index 02a12eb..56bec8f 100644 --- a/include/tsl/array_set.h +++ b/include/tsl/array_set.h @@ -96,7 +96,7 @@ class array_set { } -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW array_set(std::initializer_list> init, size_type bucket_count = ht::DEFAULT_INIT_BUCKET_COUNT, const Hash& hash = Hash()): array_set(bucket_count, hash) @@ -114,7 +114,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW array_set& operator=(std::initializer_list> ilist) { clear(); @@ -163,7 +163,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::pair insert(const std::basic_string_view& key) { return m_ht.emplace(key.data(), key.size()); } @@ -202,7 +202,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW void insert(std::initializer_list> ilist) { insert(ilist.begin(), ilist.end()); } @@ -214,7 +214,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc emplace_ks(const CharT* key, size_type key_size) */ @@ -248,7 +248,7 @@ class array_set { iterator erase(const_iterator pos) { return m_ht.erase(pos); } iterator erase(const_iterator first, const_iterator last) { return m_ht.erase(first, last); } -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW size_type erase(const std::basic_string_view& key) { return m_ht.erase(key.data(), key.size()); } @@ -267,7 +267,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc erase_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ @@ -306,7 +306,7 @@ class array_set { /* * Lookup */ -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW size_type count(const std::basic_string_view& key) const { return m_ht.count(key.data(), key.size()); } #else size_type count(const CharT* key) const { return m_ht.count(key, std::strlen(key)); } @@ -316,7 +316,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc count_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) const */ @@ -348,7 +348,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW iterator find(const std::basic_string_view& key) { return m_ht.find(key.data(), key.size()); } @@ -383,7 +383,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc find_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */ @@ -443,7 +443,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW std::pair equal_range(const std::basic_string_view& key) { return m_ht.equal_range(key.data(), key.size()); } @@ -478,7 +478,7 @@ class array_set { -#ifdef TSL_HAS_STRING_VIEW +#ifdef TSL_AH_HAS_STRING_VIEW /** * @copydoc equal_range_ks(const CharT* key, size_type key_size, std::size_t precalculated_hash) */