entity: more concepts, less sfinae

This commit is contained in:
skypjack
2026-02-04 09:14:49 +01:00
parent a77b34f929
commit a15a7653ee
2 changed files with 11 additions and 6 deletions

View File

@@ -59,7 +59,8 @@ public:
constexpr registry_storage_iterator(It iter) noexcept
: it{iter} {}
template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
template<typename Other>
requires (!std::same_as<It, Other> && std::constructible_from<It, Other>)
constexpr registry_storage_iterator(const registry_storage_iterator<Other> &other) noexcept
: registry_storage_iterator{other.it} {}
@@ -613,7 +614,8 @@ public:
* @param last An iterator past the last element of the range of entities.
* @param from An iterator to the first element of the range of elements.
*/
template<typename Type, typename EIt, typename CIt, typename = std::enable_if_t<std::is_same_v<typename std::iterator_traits<CIt>::value_type, Type>>>
template<typename Type, typename EIt, typename CIt>
requires std::same_as<typename std::iterator_traits<CIt>::value_type, Type>
void insert(EIt first, EIt last, CIt from) {
ENTT_ASSERT(std::all_of(first, last, [this](const auto entt) { return valid(entt); }), "Invalid entity");
assure<Type>().insert(first, last, from);

View File

@@ -53,8 +53,9 @@ public:
: payload{ref},
offset{idx} {}
template<bool Const = std::is_const_v<Container>, typename = std::enable_if_t<Const>>
constexpr storage_iterator(const storage_iterator<std::remove_const_t<Container>, Page> &other) noexcept
template<std::same_as<std::remove_const_t<Container>> Other>
requires std::is_const_v<Container>
constexpr storage_iterator(const storage_iterator<Other, Page> &other) noexcept
: storage_iterator{other.payload, other.offset} {}
constexpr storage_iterator &operator++() noexcept {
@@ -152,7 +153,8 @@ public:
constexpr extended_storage_iterator(iterator_type base, Other... other)
: it{base, other...} {}
template<typename... Args, typename = std::enable_if_t<(!std::is_same_v<Other, Args> && ...) && (std::is_constructible_v<Other, Args> && ...)>>
template<typename... Args>
requires (!std::same_as<Other, Args> && ...) && (std::constructible_from<Other, Args> && ...)
constexpr extended_storage_iterator(const extended_storage_iterator<It, Args...> &other)
: it{other.it} {}
@@ -715,7 +717,8 @@ public:
* @param from An iterator to the first element of the range of objects.
* @return Iterator pointing to the first element inserted, if any.
*/
template<typename EIt, typename CIt, typename = std::enable_if_t<std::is_same_v<typename std::iterator_traits<CIt>::value_type, value_type>>>
template<typename EIt, typename CIt>
requires std::same_as<typename std::iterator_traits<CIt>::value_type, value_type>
iterator insert(EIt first, EIt last, CIt from) {
for(; first != last; ++first, ++from) {
emplace_element(*first, true, *from);