Skip to content

Commit

Permalink
meta: expose basic_meta_sequence_container_traits::fixed_size
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Oct 17, 2023
1 parent 9d33ae8 commit 75bff4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TODO (high prio):
* make ::pack part of the sparse set interface
* storage-based invoke helpers (update sigh mixin to also support storage based cbs)
* make nth_argument use function types rather than pointers
* use fixed_size_sequence_container_v to skip calls in meta.hpp, make funcs ret type void
* ===> TEST: view (scoped begin) tests after the last changes

WIP:
Expand Down
33 changes: 18 additions & 15 deletions src/entt/meta/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace entt {
namespace internal {

template<typename, typename = void>
struct dynamic_sequence_container: std::false_type {};
struct fixed_size_sequence_container: std::true_type {};

template<typename Type>
struct dynamic_sequence_container<Type, std::void_t<decltype(&Type::clear)>>: std::true_type {};
struct fixed_size_sequence_container<Type, std::void_t<decltype(&Type::clear)>>: std::false_type {};

template<typename Type>
inline constexpr bool dynamic_sequence_container_v = dynamic_sequence_container<Type>::value;
inline constexpr bool fixed_size_sequence_container_v = fixed_size_sequence_container<Type>::value;

template<typename, typename = void>
struct key_only_associative_container: std::true_type {};
Expand Down Expand Up @@ -67,6 +67,9 @@ template<typename Type>
struct basic_meta_sequence_container_traits {
static_assert(std::is_same_v<Type, std::remove_cv_t<std::remove_reference_t<Type>>>, "Unexpected type");

/*! @brief True in case of key-only containers, false otherwise. */
static constexpr bool fixed_size = internal::fixed_size_sequence_container_v<Type>;

/*! @brief Unsigned integer type. */
using size_type = typename meta_sequence_container::size_type;
/*! @brief Meta iterator type. */
Expand All @@ -87,11 +90,11 @@ struct basic_meta_sequence_container_traits {
* @return True in case of success, false otherwise.
*/
[[nodiscard]] static bool clear([[maybe_unused]] void *container) {
if constexpr(internal::dynamic_sequence_container_v<Type>) {
if constexpr(fixed_size) {
return false;
} else {
static_cast<Type *>(container)->clear();
return true;
} else {
return false;
}
}

Expand All @@ -117,11 +120,11 @@ struct basic_meta_sequence_container_traits {
* @return True in case of success, false otherwise.
*/
[[nodiscard]] static bool resize([[maybe_unused]] void *container, [[maybe_unused]] const size_type sz) {
if constexpr(internal::dynamic_sequence_container_v<Type> && std::is_default_constructible_v<typename Type::value_type>) {
if constexpr(fixed_size || !std::is_default_constructible_v<typename Type::value_type>) {
return false;
} else {
static_cast<Type *>(container)->resize(sz);
return true;
} else {
return false;
}
}

Expand Down Expand Up @@ -161,16 +164,16 @@ struct basic_meta_sequence_container_traits {
* @return True in case of success, false otherwise.
*/
[[nodiscard]] static bool insert([[maybe_unused]] void *container, [[maybe_unused]] const void *value, [[maybe_unused]] const void *cref, [[maybe_unused]] iterator &it) {
if constexpr(internal::dynamic_sequence_container_v<Type>) {
if constexpr(fixed_size) {
return false;
} 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;
} else {
return false;
}
}

Expand All @@ -181,12 +184,12 @@ struct basic_meta_sequence_container_traits {
* @return True in case of success, false otherwise.
*/
[[nodiscard]] static bool erase([[maybe_unused]] void *container, [[maybe_unused]] iterator &it) {
if constexpr(internal::dynamic_sequence_container_v<Type>) {
if constexpr(fixed_size) {
return false;
} 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;
} else {
return false;
}
}
};
Expand Down

0 comments on commit 75bff4d

Please sign in to comment.