1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

clean-up containers

This commit is contained in:
neargye 2023-06-21 12:57:55 +04:00
parent 43070070e6
commit 288cb71861

View file

@ -158,19 +158,15 @@ class indexing {
static constexpr auto indices = get_indices(); static constexpr auto indices = get_indices();
public: public:
static constexpr auto& values = indices.first; [[nodiscard]] static constexpr const E* begin() noexcept { return indices.first.data(); }
[[nodiscard]] static constexpr const E* begin() noexcept { [[nodiscard]] static constexpr const E* end() noexcept { return indices.first.data() + indices.first.size(); }
return values.data();
}
[[nodiscard]] static constexpr const E* end() noexcept { [[nodiscard]] static constexpr const E* it(std::size_t i) noexcept { return &indices.first[i]; }
return values.data() + values.size();
}
[[nodiscard]] static constexpr optional<std::size_t> at(E val) noexcept { [[nodiscard]] static constexpr optional<std::size_t> at(E val) noexcept {
if (auto opt = enum_index(val)) { if (auto i = enum_index(val)) {
return indices.second[*opt]; return indices.second[*i];
} }
return {}; return {};
} }
@ -178,16 +174,14 @@ class indexing {
template <typename E, typename Cmp> template <typename E, typename Cmp>
class indexing<E, Cmp, std::enable_if_t<std::is_enum_v<std::decay_t<E>> && (std::is_same_v<Cmp, std::less<E>> || std::is_same_v<Cmp, std::less<>>)>> { class indexing<E, Cmp, std::enable_if_t<std::is_enum_v<std::decay_t<E>> && (std::is_same_v<Cmp, std::less<E>> || std::is_same_v<Cmp, std::less<>>)>> {
public:
static constexpr auto& values = enum_values<E>(); static constexpr auto& values = enum_values<E>();
[[nodiscard]] static constexpr const E* begin() noexcept { public:
return values.data(); [[nodiscard]] static constexpr const E* begin() noexcept { return values.data(); }
}
[[nodiscard]] static constexpr const E* end() noexcept { [[nodiscard]] static constexpr const E* end() noexcept { return values.data() + values.size(); }
return values.data() + values.size();
} [[nodiscard]] static constexpr const E* it(std::size_t i) noexcept { return &values[i]; }
[[nodiscard]] static constexpr optional<std::size_t> at(E val) noexcept { return enum_index(val); } [[nodiscard]] static constexpr optional<std::size_t> at(E val) noexcept { return enum_index(val); }
}; };
@ -941,7 +935,7 @@ class set {
++s; ++s;
} }
return {iterator{this, index_type::begin(), index_type::end(), &(index_type::values[*i])}, r}; return {iterator{this, index_type::begin(), index_type::end(), index_type::it(*i)}, r};
} }
return {end(), false}; return {end(), false};
} }
@ -1024,7 +1018,7 @@ class set {
[[nodiscard]] constexpr const_iterator find(const key_type& key) const noexcept { [[nodiscard]] constexpr const_iterator find(const key_type& key) const noexcept {
if (auto i = index_type::at(key); i && a.test(key)) { if (auto i = index_type::at(key); i && a.test(key)) {
return const_iterator{this, index_type::begin(), index_type::end(), &(index_type::values[*i])}; return const_iterator{this, index_type::begin(), index_type::end(), index_type::it(*i)};
} }
return end(); return end();
} }
@ -1055,7 +1049,7 @@ class set {
[[nodiscard]] constexpr const_iterator lower_bound(const key_type& key) const noexcept { [[nodiscard]] constexpr const_iterator lower_bound(const key_type& key) const noexcept {
if (auto i = index_type::at(key)) { if (auto i = index_type::at(key)) {
auto it = const_iterator{this, index_type::begin(), index_type::end(), &(index_type::values[*i])}; auto it = const_iterator{this, index_type::begin(), index_type::end(), index_type::it(*i)};
return a.test(key) ? it : std::next(it); return a.test(key) ? it : std::next(it);
} }
return end(); return end();
@ -1069,7 +1063,7 @@ class set {
[[nodiscard]] constexpr const_iterator upper_bound(const key_type& key) const noexcept { [[nodiscard]] constexpr const_iterator upper_bound(const key_type& key) const noexcept {
if (auto i = index_type::at(key)) { if (auto i = index_type::at(key)) {
return std::next(const_iterator{this, index_type::begin(), index_type::end(), &(index_type::values[*i])}); return std::next(const_iterator{this, index_type::begin(), index_type::end(), index_type::it(*i)});
} }
return end(); return end();
} }
@ -1096,8 +1090,8 @@ class set {
return false; return false;
} }
for (auto& e : index_type::values) { for (auto it = index_type::begin(); it != index_type::end(); ++it) {
if (auto c = rhs.contains(e); c != lhs.contains(e)) { if (auto c = rhs.contains(*it); c != lhs.contains(*it)) {
return c; return c;
} }
} }