Browse Source

entity: adjust noexcept policy

Michele Caini 4 năm trước cách đây
mục cha
commit
bcd16ea5ea

+ 10 - 10
src/entt/entity/group.hpp

@@ -80,7 +80,7 @@ class basic_group<Entity, owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
 
         extended_group_iterator() = default;
 
-        extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<storage_type<Get> *...> &args) ENTT_NOEXCEPT
+        extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<storage_type<Get> *...> &args)
             : it{from},
               pools{args} {}
 
@@ -255,7 +255,7 @@ public:
      * @return The first entity of the group if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type front() const {
+    [[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
         const auto it = begin();
         return it != end() ? *it : null;
     }
@@ -265,7 +265,7 @@ public:
      * @return The last entity of the group if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type back() const {
+    [[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
         const auto it = rbegin();
         return it != rend() ? *it : null;
     }
@@ -276,7 +276,7 @@ public:
      * @return An iterator to the given entity if it's found, past the end
      * iterator otherwise.
      */
-    [[nodiscard]] iterator find(const entity_type entt) const {
+    [[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
         const auto it = *this ? handler->find(entt) : iterator{};
         return it != end() && *it == entt ? it : end();
     }
@@ -303,7 +303,7 @@ public:
      * @param entt A valid identifier.
      * @return True if the group contains the given entity, false otherwise.
      */
-    [[nodiscard]] bool contains(const entity_type entt) const {
+    [[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
         return *this && handler->contains(entt);
     }
 
@@ -540,7 +540,7 @@ class basic_group<Entity, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...
         extended_group_iterator() = default;
 
         template<typename... Other>
-        extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<Other...> &other, const std::tuple<storage_type<Get> *...> &cpools) ENTT_NOEXCEPT
+        extended_group_iterator(typename basic_common_type::iterator from, const std::tuple<Other...> &other, const std::tuple<storage_type<Get> *...> &cpools)
             : it{from},
               owned{std::get<OIt>(other)...},
               get{cpools} {}
@@ -695,7 +695,7 @@ public:
      * @return The first entity of the group if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type front() const {
+    [[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
         const auto it = begin();
         return it != end() ? *it : null;
     }
@@ -705,7 +705,7 @@ public:
      * @return The last entity of the group if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type back() const {
+    [[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
         const auto it = rbegin();
         return it != rend() ? *it : null;
     }
@@ -716,7 +716,7 @@ public:
      * @return An iterator to the given entity if it's found, past the end
      * iterator otherwise.
      */
-    [[nodiscard]] iterator find(const entity_type entt) const {
+    [[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
         const auto it = *this ? std::get<0>(pools)->find(entt) : iterator{};
         return it != end() && it >= begin() && *it == entt ? it : end();
     }
@@ -743,7 +743,7 @@ public:
      * @param entt A valid identifier.
      * @return True if the group contains the given entity, false otherwise.
      */
-    [[nodiscard]] bool contains(const entity_type entt) const {
+    [[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
         return *this && std::get<0>(pools)->contains(entt) && (std::get<0>(pools)->index(entt) < (*length));
     }
 

+ 6 - 6
src/entt/entity/registry.hpp

@@ -59,7 +59,7 @@ public:
         : it{iter} {}
 
     template<typename Other, typename = std::enable_if_t<!std::is_same_v<It, Other> && std::is_constructible_v<It, Other>>>
-    storage_proxy_iterator(const storage_proxy_iterator<Other> &other)
+    storage_proxy_iterator(const storage_proxy_iterator<Other> &other) ENTT_NOEXCEPT
         : it{other.it} {}
 
     storage_proxy_iterator &operator++() ENTT_NOEXCEPT {
@@ -98,15 +98,15 @@ public:
         return (*this + -value);
     }
 
-    [[nodiscard]] reference operator[](const difference_type value) const {
+    [[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
         return {it[value].first, *it[value].second};
     }
 
-    [[nodiscard]] reference operator*() const {
+    [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
         return {it->first, *it->second};
     }
 
-    [[nodiscard]] pointer operator->() const {
+    [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
         return operator*();
     }
 
@@ -340,7 +340,7 @@ public:
      * @brief Move constructor.
      * @param other The instance to move from.
      */
-    basic_registry(basic_registry &&other) ENTT_NOEXCEPT
+    basic_registry(basic_registry &&other)
         : pools{std::move(other.pools)},
           groups{std::move(other.groups)},
           entities{std::move(other.entities)},
@@ -356,7 +356,7 @@ public:
      * @param other The instance to move from.
      * @return This registry.
      */
-    basic_registry &operator=(basic_registry &&other) ENTT_NOEXCEPT {
+    basic_registry &operator=(basic_registry &&other) {
         pools = std::move(other.pools);
         groups = std::move(other.groups);
         entities = std::move(other.entities);

+ 4 - 4
src/entt/entity/runtime_view.hpp

@@ -58,21 +58,21 @@ public:
         return ++(*this), orig;
     }
 
-    runtime_view_iterator &operator--() ENTT_NOEXCEPT {
+    runtime_view_iterator &operator--() {
         while(--it != (*pools)[0]->begin() && !valid()) {}
         return *this;
     }
 
-    runtime_view_iterator operator--(int) ENTT_NOEXCEPT {
+    runtime_view_iterator operator--(int) {
         runtime_view_iterator orig = *this;
         return operator--(), orig;
     }
 
-    [[nodiscard]] pointer operator->() const {
+    [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
         return it.operator->();
     }
 
-    [[nodiscard]] reference operator*() const {
+    [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
         return *operator->();
     }
 

+ 4 - 4
src/entt/entity/snapshot.hpp

@@ -71,10 +71,10 @@ public:
         : reg{&source} {}
 
     /*! @brief Default move constructor. */
-    basic_snapshot(basic_snapshot &&) = default;
+    basic_snapshot(basic_snapshot &&) ENTT_NOEXCEPT = default;
 
     /*! @brief Default move assignment operator. @return This snapshot. */
-    basic_snapshot &operator=(basic_snapshot &&) = default;
+    basic_snapshot &operator=(basic_snapshot &&) ENTT_NOEXCEPT = default;
 
     /**
      * @brief Puts aside all the entities from the underlying registry.
@@ -202,10 +202,10 @@ public:
     }
 
     /*! @brief Default move constructor. */
-    basic_snapshot_loader(basic_snapshot_loader &&) = default;
+    basic_snapshot_loader(basic_snapshot_loader &&) ENTT_NOEXCEPT = default;
 
     /*! @brief Default move assignment operator. @return This loader. */
-    basic_snapshot_loader &operator=(basic_snapshot_loader &&) = default;
+    basic_snapshot_loader &operator=(basic_snapshot_loader &&) ENTT_NOEXCEPT = default;
 
     /**
      * @brief Restores entities that were in use during serialization.

+ 4 - 4
src/entt/entity/sparse_set.hpp

@@ -74,15 +74,15 @@ struct sparse_set_iterator final {
         return (*this + -value);
     }
 
-    [[nodiscard]] reference operator[](const difference_type value) const {
+    [[nodiscard]] reference operator[](const difference_type value) const ENTT_NOEXCEPT {
         return packed->data()[index() - value];
     }
 
-    [[nodiscard]] pointer operator->() const {
+    [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
         return packed->data() + index();
     }
 
-    [[nodiscard]] reference operator*() const {
+    [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
         return *operator->();
     }
 
@@ -585,7 +585,7 @@ public:
      * @return The version for the given identifier if present, the tombstone
      * version otherwise.
      */
-    [[nodiscard]] version_type current(const entity_type entt) const {
+    [[nodiscard]] version_type current(const entity_type entt) const ENTT_NOEXCEPT {
         const auto elem = sparse_ptr(entt);
         constexpr auto fallback = entity_traits::to_version(tombstone);
         return elem ? entity_traits::to_version(*elem) : fallback;

+ 2 - 2
src/entt/entity/storage.hpp

@@ -170,11 +170,11 @@ public:
 
     extended_storage_iterator() = default;
 
-    extended_storage_iterator(It base, Other... other) ENTT_NOEXCEPT
+    extended_storage_iterator(It 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> && ...)>>
-    extended_storage_iterator(const extended_storage_iterator<It, Args...> &other) ENTT_NOEXCEPT
+    extended_storage_iterator(const extended_storage_iterator<It, Args...> &other)
         : it{other.it} {}
 
     extended_storage_iterator &operator++() ENTT_NOEXCEPT {

+ 15 - 19
src/entt/entity/view.hpp

@@ -28,7 +28,7 @@ namespace internal {
 
 template<typename Type, std::size_t Component, std::size_t Exclude>
 class view_iterator final {
-    [[nodiscard]] bool valid() const {
+    [[nodiscard]] bool valid() const ENTT_NOEXCEPT {
         return ((Component != 0u) || (*it != tombstone))
                && std::apply([entt = *it](const auto *...curr) { return (curr->contains(entt) && ...); }, pools)
                && std::apply([entt = *it](const auto *...curr) { return (!curr->contains(entt) && ...); }, filter);
@@ -42,11 +42,7 @@ public:
     using reference = typename std::iterator_traits<iterator_type>::reference;
     using iterator_category = std::forward_iterator_tag;
 
-    view_iterator() ENTT_NOEXCEPT
-        : it{},
-          last{},
-          pools{},
-          filter{} {}
+    view_iterator() ENTT_NOEXCEPT = default;
 
     view_iterator(iterator_type curr, iterator_type to, std::array<const Type *, Component> all_of, std::array<const Type *, Exclude> none_of) ENTT_NOEXCEPT
         : it{curr},
@@ -68,11 +64,11 @@ public:
         return ++(*this), orig;
     }
 
-    [[nodiscard]] pointer operator->() const {
+    [[nodiscard]] pointer operator->() const ENTT_NOEXCEPT {
         return &*it;
     }
 
-    [[nodiscard]] reference operator*() const {
+    [[nodiscard]] reference operator*() const ENTT_NOEXCEPT {
         return *operator->();
     }
 
@@ -106,7 +102,7 @@ struct extended_view_iterator final {
 
     extended_view_iterator() = default;
 
-    extended_view_iterator(It from, std::tuple<Storage *...> storage) ENTT_NOEXCEPT
+    extended_view_iterator(It from, std::tuple<Storage *...> storage)
         : it{from},
           pools{storage} {}
 
@@ -328,7 +324,7 @@ public:
      *
      * @return An iterator to the first entity of the view.
      */
-    [[nodiscard]] iterator begin() const {
+    [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
         return iterator{view->begin(), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter};
     }
 
@@ -341,7 +337,7 @@ public:
      *
      * @return An iterator to the entity following the last entity of the view.
      */
-    [[nodiscard]] iterator end() const {
+    [[nodiscard]] iterator end() const ENTT_NOEXCEPT {
         return iterator{view->end(), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter};
     }
 
@@ -350,7 +346,7 @@ public:
      * @return The first entity of the view if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type front() const {
+    [[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
         const auto it = begin();
         return it != end() ? *it : null;
     }
@@ -360,7 +356,7 @@ public:
      * @return The last entity of the view if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type back() const {
+    [[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
         auto it = view->rbegin();
         for(const auto last = view->rend(); it != last && !contains(*it); ++it) {}
         return it == view->rend() ? null : *it;
@@ -372,7 +368,7 @@ public:
      * @return An iterator to the given entity if it's found, past the end
      * iterator otherwise.
      */
-    [[nodiscard]] iterator find(const entity_type entt) const {
+    [[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
         return contains(entt) ? iterator{view->find(entt), view->end(), pools_to_array(std::index_sequence_for<Component...>{}), filter} : end();
     }
 
@@ -398,7 +394,7 @@ public:
      * @param entt A valid identifier.
      * @return True if the view contains the given entity, false otherwise.
      */
-    [[nodiscard]] bool contains(const entity_type entt) const {
+    [[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
         return std::apply([entt](const auto *...curr) { return (curr->contains(entt) && ...); }, pools)
                && std::apply([entt](const auto *...curr) { return (!curr->contains(entt) && ...); }, filter);
     }
@@ -669,7 +665,7 @@ public:
      * @return The first entity of the view if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type front() const {
+    [[nodiscard]] entity_type front() const ENTT_NOEXCEPT {
         return empty() ? null : *begin();
     }
 
@@ -678,7 +674,7 @@ public:
      * @return The last entity of the view if one exists, the null entity
      * otherwise.
      */
-    [[nodiscard]] entity_type back() const {
+    [[nodiscard]] entity_type back() const ENTT_NOEXCEPT {
         return empty() ? null : *rbegin();
     }
 
@@ -688,7 +684,7 @@ public:
      * @return An iterator to the given entity if it's found, past the end
      * iterator otherwise.
      */
-    [[nodiscard]] iterator find(const entity_type entt) const {
+    [[nodiscard]] iterator find(const entity_type entt) const ENTT_NOEXCEPT {
         return contains(entt) ? view->find(entt) : end();
     }
 
@@ -723,7 +719,7 @@ public:
      * @param entt A valid identifier.
      * @return True if the view contains the given entity, false otherwise.
      */
-    [[nodiscard]] bool contains(const entity_type entt) const {
+    [[nodiscard]] bool contains(const entity_type entt) const ENTT_NOEXCEPT {
         return view->contains(entt);
     }