|
|
@@ -13,6 +13,7 @@
|
|
|
#include <vector>
|
|
|
#include "../container/dense_map.hpp"
|
|
|
#include "../container/dense_set.hpp"
|
|
|
+#include "context.hpp"
|
|
|
#include "meta.hpp"
|
|
|
#include "type_traits.hpp"
|
|
|
|
|
|
@@ -130,70 +131,64 @@ struct basic_meta_sequence_container_traits {
|
|
|
|
|
|
/**
|
|
|
* @brief Returns a possibly const iterator to the beginning.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param as_const True for const-only containers, false otherwise.
|
|
|
- * @param it The meta iterator to rebind the underlying iterator to.
|
|
|
+ * @return An iterator to the first element of the container.
|
|
|
*/
|
|
|
- static void begin(const void *container, const bool as_const, iterator &it) {
|
|
|
- if(as_const) {
|
|
|
- it.rebind(static_cast<const Type *>(container)->begin());
|
|
|
- } else {
|
|
|
- it.rebind(static_cast<Type *>(const_cast<void *>(container))->begin());
|
|
|
- }
|
|
|
+ static iterator begin(const meta_ctx &area, const void *container, const bool as_const) {
|
|
|
+ return as_const ? iterator{area, static_cast<const Type *>(container)->begin()}
|
|
|
+ : iterator{area, static_cast<Type *>(const_cast<void *>(container))->begin()};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Returns a possibly const iterator to the end.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param as_const True for const-only containers, false otherwise.
|
|
|
- * @param it The meta iterator to rebind the underlying iterator to.
|
|
|
+ * @return An iterator that is past the last element of the container.
|
|
|
*/
|
|
|
- static void end(const void *container, const bool as_const, iterator &it) {
|
|
|
- if(as_const) {
|
|
|
- it.rebind(static_cast<const Type *>(container)->end());
|
|
|
- } else {
|
|
|
- it.rebind(static_cast<Type *>(const_cast<void *>(container))->end());
|
|
|
- }
|
|
|
+ static iterator end(const meta_ctx &area, const void *container, const bool as_const) {
|
|
|
+ return as_const ? iterator{area, static_cast<const Type *>(container)->end()}
|
|
|
+ : iterator{area, static_cast<Type *>(const_cast<void *>(container))->end()};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Assigns one element to a container and constructs its object from
|
|
|
* a given opaque instance.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param value Optional opaque instance of the object to construct (as
|
|
|
* value type).
|
|
|
* @param cref Optional opaque instance of the object to construct (as
|
|
|
* decayed const reference type).
|
|
|
* @param it Iterator before which the element will be inserted.
|
|
|
- * @return True in case of success, false otherwise.
|
|
|
+ * @return A possibly invalid iterator to the inserted element.
|
|
|
*/
|
|
|
- [[nodiscard]] static bool insert([[maybe_unused]] void *container, [[maybe_unused]] const void *value, [[maybe_unused]] const void *cref, [[maybe_unused]] iterator &it) {
|
|
|
+ [[nodiscard]] static iterator insert([[maybe_unused]] const meta_ctx &area, [[maybe_unused]] void *container, [[maybe_unused]] const void *value, [[maybe_unused]] const void *cref, [[maybe_unused]] const iterator &it) {
|
|
|
if constexpr(fixed_size) {
|
|
|
- return false;
|
|
|
+ return iterator{area};
|
|
|
} else {
|
|
|
auto *const non_const = any_cast<typename Type::iterator>(&it.base());
|
|
|
-
|
|
|
- it.rebind(static_cast<Type *>(container)->insert(
|
|
|
- non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base()),
|
|
|
- value ? *static_cast<const typename Type::value_type *>(value) : *static_cast<const std::remove_reference_t<typename Type::const_reference> *>(cref)));
|
|
|
-
|
|
|
- return true;
|
|
|
+ return {area, static_cast<Type *>(container)->insert(
|
|
|
+ non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base()),
|
|
|
+ value ? *static_cast<const typename Type::value_type *>(value) : *static_cast<const std::remove_reference_t<typename Type::const_reference> *>(cref))};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Erases an element from a container.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param it An opaque iterator to the element to erase.
|
|
|
- * @return True in case of success, false otherwise.
|
|
|
+ * @return A possibly invalid iterator following the last removed element.
|
|
|
*/
|
|
|
- [[nodiscard]] static bool erase([[maybe_unused]] void *container, [[maybe_unused]] iterator &it) {
|
|
|
+ [[nodiscard]] static iterator erase([[maybe_unused]] const meta_ctx &area, [[maybe_unused]] void *container, [[maybe_unused]] const iterator &it) {
|
|
|
if constexpr(fixed_size) {
|
|
|
- return false;
|
|
|
+ return iterator{area};
|
|
|
} else {
|
|
|
auto *const non_const = any_cast<typename Type::iterator>(&it.base());
|
|
|
- it.rebind(static_cast<Type *>(container)->erase(non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base())));
|
|
|
- return true;
|
|
|
+ return {area, static_cast<Type *>(container)->erase(non_const ? *non_const : any_cast<const typename Type::const_iterator &>(it.base()))};
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
@@ -250,30 +245,26 @@ struct basic_meta_associative_container_traits {
|
|
|
|
|
|
/**
|
|
|
* @brief Returns a possibly const iterator to the beginning.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param as_const True for const-only containers, false otherwise.
|
|
|
- * @param it The meta iterator to rebind the underlying iterator to.
|
|
|
+ * @return An iterator to the first element of the container.
|
|
|
*/
|
|
|
- static void begin(const void *container, const bool as_const, iterator &it) {
|
|
|
- if(as_const) {
|
|
|
- it.rebind<key_only>(static_cast<const Type *>(container)->begin());
|
|
|
- } else {
|
|
|
- it.rebind<key_only>(static_cast<Type *>(const_cast<void *>(container))->begin());
|
|
|
- }
|
|
|
+ static iterator begin(const meta_ctx &area, const void *container, const bool as_const) {
|
|
|
+ return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->begin()}
|
|
|
+ : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->begin()};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Returns a possibly const iterator to the end.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param as_const True for const-only containers, false otherwise.
|
|
|
- * @param it The meta iterator to rebind the underlying iterator to.
|
|
|
+ * @return An iterator that is past the last element of the container.
|
|
|
*/
|
|
|
- static void end(const void *container, const bool as_const, iterator &it) {
|
|
|
- if(as_const) {
|
|
|
- it.rebind<key_only>(static_cast<const Type *>(container)->end());
|
|
|
- } else {
|
|
|
- it.rebind<key_only>(static_cast<Type *>(const_cast<void *>(container))->end());
|
|
|
- }
|
|
|
+ static iterator end(const meta_ctx &area, const void *container, const bool as_const) {
|
|
|
+ return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->end()}
|
|
|
+ : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->end()};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -303,17 +294,15 @@ struct basic_meta_associative_container_traits {
|
|
|
|
|
|
/**
|
|
|
* @brief Finds an element with a given key.
|
|
|
+ * @param area The context to pass to the newly created iterator.
|
|
|
* @param container Opaque pointer to a container of the given type.
|
|
|
* @param as_const True for const-only containers, false otherwise.
|
|
|
* @param key Opaque key value of an element to search for.
|
|
|
- * @param it The meta iterator to rebind the underlying iterator to.
|
|
|
+ * @return An iterator to the element with the given key, if any.
|
|
|
*/
|
|
|
- static void find(const void *container, const bool as_const, const void *key, iterator &it) {
|
|
|
- if(const auto &elem = *static_cast<const typename Type::key_type *>(key); as_const) {
|
|
|
- it.rebind<key_only>(static_cast<const Type *>(container)->find(elem));
|
|
|
- } else {
|
|
|
- it.rebind<key_only>(static_cast<Type *>(const_cast<void *>(container))->find(elem));
|
|
|
- }
|
|
|
+ static iterator find(const meta_ctx &area, const void *container, const bool as_const, const void *key) {
|
|
|
+ return as_const ? iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(container)->find(*static_cast<const typename Type::key_type *>(key))}
|
|
|
+ : iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(const_cast<void *>(container))->find(*static_cast<const typename Type::key_type *>(key))};
|
|
|
}
|
|
|
};
|
|
|
|