meta: context aware meta associative container
This commit is contained in:
@@ -114,15 +114,13 @@ struct basic_meta_associative_container_traits {
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator iter(any &container, const bool as_end) {
|
||||
// TODO
|
||||
|
||||
[[nodiscard]] static iterator iter(const meta_ctx &ctx, any &container, const bool as_end) {
|
||||
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||
return iterator{std::bool_constant<key_only>{}, as_end ? cont->end() : cont->begin()};
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, as_end ? cont->end() : cont->begin()};
|
||||
}
|
||||
|
||||
const auto &as_const = any_cast<const Type &>(container);
|
||||
return iterator{std::bool_constant<key_only>{}, as_end ? as_const.end() : as_const.begin()};
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, as_end ? as_const.end() : as_const.begin()};
|
||||
}
|
||||
|
||||
[[nodiscard]] static size_type insert_or_erase(any &container, meta_any &key, meta_any &value) {
|
||||
@@ -141,15 +139,13 @@ struct basic_meta_associative_container_traits {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
[[nodiscard]] static iterator find(any &container, meta_any &key) {
|
||||
// TODO
|
||||
|
||||
[[nodiscard]] static iterator find(const meta_ctx &ctx, any &container, meta_any &key) {
|
||||
if(key.allow_cast<const typename Type::key_type &>()) {
|
||||
if(auto *const cont = any_cast<Type>(&container); cont) {
|
||||
return iterator{std::bool_constant<key_only>{}, cont->find(key.cast<const typename Type::key_type &>())};
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, cont->find(key.cast<const typename Type::key_type &>())};
|
||||
}
|
||||
|
||||
return iterator{std::bool_constant<key_only>{}, any_cast<const Type &>(container).find(key.cast<const typename Type::key_type &>())};
|
||||
return iterator{ctx, std::bool_constant<key_only>{}, any_cast<const Type &>(container).find(key.cast<const typename Type::key_type &>())};
|
||||
}
|
||||
|
||||
return iterator{};
|
||||
|
||||
@@ -139,9 +139,9 @@ private:
|
||||
internal::meta_type_node (*value_type_node)(const internal::meta_context &){};
|
||||
size_type (*size_fn)(const any &) noexcept {};
|
||||
bool (*clear_fn)(any &){};
|
||||
iterator (*iter_fn)(any &, const bool){};
|
||||
iterator (*iter_fn)(const meta_ctx &, any &, const bool){};
|
||||
size_type (*insert_or_erase_fn)(any &, meta_any &, meta_any &){};
|
||||
iterator (*find_fn)(any &, meta_any &){};
|
||||
iterator (*find_fn)(const meta_ctx &, any &, meta_any &){};
|
||||
any storage{};
|
||||
};
|
||||
|
||||
@@ -1733,12 +1733,14 @@ public:
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
constexpr meta_iterator() noexcept
|
||||
: vtable{},
|
||||
: ctx{},
|
||||
vtable{},
|
||||
handle{} {}
|
||||
|
||||
template<bool KeyOnly, typename It>
|
||||
meta_iterator(std::integral_constant<bool, KeyOnly>, It iter) noexcept
|
||||
: vtable{&basic_vtable<KeyOnly, It>},
|
||||
meta_iterator(const meta_ctx &area, std::integral_constant<bool, KeyOnly>, It iter) noexcept
|
||||
: ctx{&area},
|
||||
vtable{&basic_vtable<KeyOnly, It>},
|
||||
handle{std::move(iter)} {}
|
||||
|
||||
meta_iterator &operator++() noexcept {
|
||||
@@ -1752,8 +1754,7 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] reference operator*() const {
|
||||
// TODO
|
||||
reference other;
|
||||
reference other{{meta_ctx_arg, *ctx}, {meta_ctx_arg, *ctx}};
|
||||
vtable(operation::deref, handle, &other);
|
||||
return other;
|
||||
}
|
||||
@@ -1775,6 +1776,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const meta_ctx *ctx;
|
||||
vtable_type *vtable;
|
||||
any handle;
|
||||
};
|
||||
@@ -1913,12 +1915,12 @@ inline bool meta_associative_container::clear() {
|
||||
|
||||
/*! @copydoc meta_sequence_container::begin */
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::begin() {
|
||||
return iter_fn(storage, false);
|
||||
return iter_fn(*ctx, storage, false);
|
||||
}
|
||||
|
||||
/*! @copydoc meta_sequence_container::end */
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::end() {
|
||||
return iter_fn(storage, true);
|
||||
return iter_fn(*ctx, storage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1948,7 +1950,7 @@ inline meta_associative_container::size_type meta_associative_container::erase(m
|
||||
* @return An iterator to the element with the given key, if any.
|
||||
*/
|
||||
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::find(meta_any key) {
|
||||
return find_fn(storage, key);
|
||||
return find_fn(*ctx, storage, key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user