diff --git a/include/frozen/algorithm.h b/include/frozen/algorithm.h index a538f7c..7e02c5a 100644 --- a/include/frozen/algorithm.h +++ b/include/frozen/algorithm.h @@ -28,13 +28,11 @@ #error \ "frozen/algorithm.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/algorithm.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/basic_types.h" -#include "frozen/bits/version.h" -#include "frozen/string.h" +#include "bits/basic_types.h" namespace frozen { diff --git a/include/frozen/bits/algorithms.h b/include/frozen/bits/algorithms.h index 310c31d..fc792f6 100644 --- a/include/frozen/bits/algorithms.h +++ b/include/frozen/bits/algorithms.h @@ -22,7 +22,7 @@ #pragma once -#include "frozen/bits/basic_types.h" +#include "basic_types.h" #include #include diff --git a/include/frozen/bits/basic_types.h b/include/frozen/bits/basic_types.h index 817908f..336229e 100644 --- a/include/frozen/bits/basic_types.h +++ b/include/frozen/bits/basic_types.h @@ -22,8 +22,8 @@ #pragma once -#include "frozen/bits/constexpr_assert.h" -#include "frozen/bits/exceptions.h" +#include "constexpr_assert.h" +#include "exceptions.h" #include #include diff --git a/include/frozen/bits/pmh.h b/include/frozen/bits/pmh.h index 7591886..16f6d26 100644 --- a/include/frozen/bits/pmh.h +++ b/include/frozen/bits/pmh.h @@ -23,8 +23,8 @@ // inspired from http://stevehanov.ca/blog/index.php?id=119 #pragma once -#include "frozen/bits/algorithms.h" -#include "frozen/bits/basic_types.h" +#include "algorithms.h" +#include "basic_types.h" #include #include diff --git a/include/frozen/bits/version.h b/include/frozen/bits/version.h index a6278df..0d1e83f 100644 --- a/include/frozen/bits/version.h +++ b/include/frozen/bits/version.h @@ -27,7 +27,7 @@ #if _MSVC_LANG < 202302L #error "frozen 2.0 requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen 2.0 requires C++23 or later. Compile with -std=c++23 or later." #endif diff --git a/include/frozen/map.h b/include/frozen/map.h index 733b51a..74dbcae 100644 --- a/include/frozen/map.h +++ b/include/frozen/map.h @@ -27,15 +27,14 @@ #if _MSVC_LANG < 202302L #error "frozen/map.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/map.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/algorithms.h" -#include "frozen/bits/basic_types.h" -#include "frozen/bits/exceptions.h" -#include "frozen/bits/mpl.h" -#include "frozen/bits/version.h" +#include "bits/algorithms.h" +#include "bits/basic_types.h" +#include "bits/exceptions.h" +#include "bits/mpl.h" #include #include diff --git a/include/frozen/random.h b/include/frozen/random.h index 1d41232..3c3681c 100644 --- a/include/frozen/random.h +++ b/include/frozen/random.h @@ -27,12 +27,11 @@ #if _MSVC_LANG < 202302L #error "frozen/random.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/random.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/algorithms.h" -#include "frozen/bits/version.h" +#include "bits/algorithms.h" #include #include diff --git a/include/frozen/set.h b/include/frozen/set.h index 2ee4195..dee8f0e 100644 --- a/include/frozen/set.h +++ b/include/frozen/set.h @@ -27,13 +27,12 @@ #if _MSVC_LANG < 202302L #error "frozen/set.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/set.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/algorithms.h" -#include "frozen/bits/basic_types.h" -#include "frozen/bits/version.h" +#include "bits/algorithms.h" +#include "bits/basic_types.h" #include #include @@ -101,9 +100,10 @@ namespace frozen { const_iterator where = lower_bound(key); if ((where != end()) && !value_comp()(key, *where)) + { return where; - else - return end(); + } + return end(); } template @@ -118,9 +118,10 @@ namespace frozen { auto const lower = lower_bound(key); if (lower == end()) + { return { lower, lower }; - else - return { lower, lower + 1 }; + } + return { lower, lower + 1 }; } template @@ -128,9 +129,10 @@ namespace frozen { auto const where = bits::lower_bound(keys_.begin(), key, value_comp()); if ((where != end()) && !value_comp()(key, *where)) + { return where; - else - return end(); + } + return end(); } template @@ -138,9 +140,10 @@ namespace frozen { auto const where = bits::lower_bound(keys_.begin(), key, value_comp()); if ((where != end()) && !value_comp()(key, *where)) + { return where + 1; - else - return end(); + } + return end(); } /* observers */ diff --git a/include/frozen/string.h b/include/frozen/string.h index 71ad52d..ff2d85b 100644 --- a/include/frozen/string.h +++ b/include/frozen/string.h @@ -1,6 +1,14 @@ #pragma once -#include "frozen/bits/version.h" +// Require C++23 or later +#if defined(_MSVC_LANG) + #if _MSVC_LANG < 202302L + #error \ + "frozen/unordered_map.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." + #endif +#elif __cplusplus < 202101L + #error "frozen/unordered_map.h requires C++23 or later. Compile with -std=c++23 or later." +#endif #include #include diff --git a/include/frozen/unordered_map.h b/include/frozen/unordered_map.h index cacea20..13e33e1 100644 --- a/include/frozen/unordered_map.h +++ b/include/frozen/unordered_map.h @@ -28,19 +28,17 @@ #error \ "frozen/unordered_map.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/unordered_map.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/basic_types.h" -#include "frozen/bits/elsa.h" -#include "frozen/bits/exceptions.h" -#include "frozen/bits/pmh.h" -#include "frozen/bits/version.h" -#include "frozen/random.h" +#include "bits/basic_types.h" +#include "bits/elsa.h" +#include "bits/exceptions.h" +#include "bits/pmh.h" +#include "random.h" #include -#include #include namespace frozen diff --git a/include/frozen/unordered_set.h b/include/frozen/unordered_set.h index 4d19112..c0e151a 100644 --- a/include/frozen/unordered_set.h +++ b/include/frozen/unordered_set.h @@ -28,15 +28,14 @@ #error \ "frozen/unordered_set.h requires C++23 or later. Compile with /std:c++latest or /std:c++23." #endif -#elif __cplusplus < 202302L +#elif __cplusplus < 202101L #error "frozen/unordered_set.h requires C++23 or later. Compile with -std=c++23 or later." #endif -#include "frozen/bits/basic_types.h" -#include "frozen/bits/elsa.h" -#include "frozen/bits/pmh.h" -#include "frozen/bits/version.h" -#include "frozen/random.h" +#include "bits/basic_types.h" +#include "bits/elsa.h" +#include "bits/pmh.h" +#include "random.h" #include #include @@ -50,7 +49,7 @@ namespace frozen struct Get { template - constexpr T const& operator()(T const& key) const + constexpr auto operator()(T const& key) const -> T const& { return key; } @@ -85,7 +84,6 @@ namespace frozen using const_iterator = typename container_type::const_iterator; using iterator = const_iterator; - public: /* constructors */ unordered_set(unordered_set const&) = default; constexpr unordered_set(container_type keys, Hash const& hash, KeyEqual const& equal) : @@ -111,72 +109,79 @@ namespace frozen } /* iterators */ - [[nodiscard]] constexpr const_iterator begin() const { return keys_.begin(); } - [[nodiscard]] constexpr const_iterator end() const { return keys_.end(); } - [[nodiscard]] constexpr const_iterator cbegin() const { return keys_.begin(); } - [[nodiscard]] constexpr const_iterator cend() const { return keys_.end(); } + [[nodiscard]] constexpr auto begin() const -> const_iterator { return keys_.begin(); } + [[nodiscard]] constexpr auto end() const -> const_iterator { return keys_.end(); } + [[nodiscard]] constexpr auto cbegin() const -> const_iterator { return keys_.begin(); } + [[nodiscard]] constexpr auto cend() const -> const_iterator { return keys_.end(); } /* capacity */ - [[nodiscard]] constexpr bool empty() const { return !N; } - [[nodiscard]] constexpr size_type size() const { return N; } - [[nodiscard]] constexpr size_type max_size() const { return N; } + [[nodiscard]] constexpr auto empty() const -> bool { return !N; } + [[nodiscard]] constexpr auto size() const -> size_type { return N; } + [[nodiscard]] constexpr auto max_size() const -> size_type { return N; } /* lookup */ template - [[nodiscard]] constexpr std::size_t count(KeyType const& key) const + [[nodiscard]] constexpr auto count(KeyType const& key) const -> std::size_t { return find(key, hash_function(), key_eq()) != end(); } template - [[nodiscard]] constexpr const_iterator find(KeyType const& key, Hasher const& hash, - Equal const& equal) const + [[nodiscard]] constexpr auto find(KeyType const& key, Hasher const& hash, + Equal const& equal) const -> const_iterator { auto const pos = tables_.lookup(key, hash); - auto it = keys_.begin() + pos; - if (it != keys_.end() && equal(*it, key)) - return it; - else - return keys_.end(); + auto iter = keys_.begin() + pos; + if (iter != keys_.end() && equal(*iter, key)) + { + return iter; + } + return keys_.end(); } + template - [[nodiscard]] constexpr const_iterator find(KeyType const& key) const + [[nodiscard]] constexpr auto find(KeyType const& key) const -> const_iterator { auto const pos = tables_.lookup(key, hash_function()); - auto it = keys_.begin() + pos; - if (it != keys_.end() && key_eq()(*it, key)) - return it; - else - return keys_.end(); + auto iter = keys_.begin() + pos; + if (iter != keys_.end() && key_eq()(*iter, key)) + { + return iter; + } + return keys_.end(); } template - [[nodiscard]] constexpr bool contains(KeyType const& key) const + [[nodiscard]] constexpr auto contains(KeyType const& key) const -> bool { return this->find(key) != keys_.end(); } template - [[nodiscard]] constexpr std::pair - equal_range(KeyType const& key) const + [[nodiscard]] constexpr auto equal_range(KeyType const& key) const + -> std::pair { - auto const it = find(key); - if (it != end()) - return { it, it + 1 }; - else - return { keys_.end(), keys_.end() }; + auto const iter = find(key); + if (iter != end()) + { + return { iter, iter + 1 }; + } + return { keys_.end(), keys_.end() }; } /* bucket interface */ - [[nodiscard]] constexpr std::size_t bucket_count() const { return storage_size; } - [[nodiscard]] constexpr std::size_t max_bucket_count() const { return storage_size; } + [[nodiscard]] constexpr auto bucket_count() const -> std::size_t { return storage_size; } + [[nodiscard]] constexpr auto max_bucket_count() const -> std::size_t + { + return storage_size; + } /* observers*/ - [[nodiscard]] constexpr const hasher& hash_function() const + [[nodiscard]] constexpr auto hash_function() const -> const hasher& { return tables_.hash_function(); } - [[nodiscard]] constexpr const key_equal& key_eq() const + [[nodiscard]] constexpr auto key_eq() const -> const key_equal& { return static_cast(*this); }