Browse Source

resource: [[nodiscard]] (see #501)

Michele Caini 5 years ago
parent
commit
167eadf699
3 changed files with 15 additions and 15 deletions
  1. 5 5
      src/entt/resource/cache.hpp
  2. 9 9
      src/entt/resource/handle.hpp
  3. 1 1
      src/entt/resource/loader.hpp

+ 5 - 5
src/entt/resource/cache.hpp

@@ -46,7 +46,7 @@ struct cache {
      * @brief Number of resources managed by a cache.
      * @return Number of resources currently stored.
      */
-    size_type size() const ENTT_NOEXCEPT {
+    [[nodiscard]] size_type size() const ENTT_NOEXCEPT {
         return resources.size();
     }
 
@@ -54,7 +54,7 @@ struct cache {
      * @brief Returns true if a cache contains no resources, false otherwise.
      * @return True if the cache contains no resources, false otherwise.
      */
-    bool empty() const ENTT_NOEXCEPT {
+    [[nodiscard]] bool empty() const ENTT_NOEXCEPT {
         return resources.empty();
     }
 
@@ -148,7 +148,7 @@ struct cache {
      * @return A handle for the given resource.
      */
     template<typename Loader, typename... Args>
-    entt::handle<Resource> temp(Args &&... args) const {
+    [[nodiscard]] entt::handle<Resource> temp(Args &&... args) const {
         return { Loader{}.get(std::forward<Args>(args)...) };
     }
 
@@ -165,7 +165,7 @@ struct cache {
      * @param id Unique resource identifier.
      * @return A handle for the given resource.
      */
-    entt::handle<Resource> handle(const id_type id) const {
+    [[nodiscard]] entt::handle<Resource> handle(const id_type id) const {
         auto it = resources.find(id);
         return { it == resources.end() ? nullptr : it->second };
     }
@@ -175,7 +175,7 @@ struct cache {
      * @param id Unique resource identifier.
      * @return True if the cache contains the resource, false otherwise.
      */
-    bool contains(const id_type id) const {
+    [[nodiscard]] bool contains(const id_type id) const {
         return (resources.find(id) != resources.cend());
     }
 

+ 9 - 9
src/entt/resource/handle.hpp

@@ -46,27 +46,27 @@ public:
      *
      * @return A reference to the managed resource.
      */
-    const Resource & get() const ENTT_NOEXCEPT {
+    [[nodiscard]] const Resource & get() const ENTT_NOEXCEPT {
         ENTT_ASSERT(static_cast<bool>(resource));
         return *resource;
     }
 
     /*! @copydoc get */
-    Resource & get() ENTT_NOEXCEPT {
+    [[nodiscard]] Resource & get() ENTT_NOEXCEPT {
         return const_cast<Resource &>(std::as_const(*this).get());
     }
 
     /*! @copydoc get */
-    operator const Resource & () const ENTT_NOEXCEPT { return get(); }
+    [[nodiscard]] operator const Resource & () const ENTT_NOEXCEPT { return get(); }
 
     /*! @copydoc get */
-    operator Resource & () ENTT_NOEXCEPT { return get(); }
+    [[nodiscard]] operator Resource & () ENTT_NOEXCEPT { return get(); }
 
     /*! @copydoc get */
-    const Resource & operator *() const ENTT_NOEXCEPT { return get(); }
+    [[nodiscard]] const Resource & operator *() const ENTT_NOEXCEPT { return get(); }
 
     /*! @copydoc get */
-    Resource & operator *() ENTT_NOEXCEPT { return get(); }
+    [[nodiscard]] Resource & operator *() ENTT_NOEXCEPT { return get(); }
 
     /**
      * @brief Gets a pointer to the managed resource.
@@ -79,13 +79,13 @@ public:
      * @return A pointer to the managed resource or `nullptr` if the handle
      * contains no resource at all.
      */
-    const Resource * operator->() const ENTT_NOEXCEPT {
+    [[nodiscard]] const Resource * operator->() const ENTT_NOEXCEPT {
         ENTT_ASSERT(static_cast<bool>(resource));
         return resource.get();
     }
 
     /*! @copydoc operator-> */
-    Resource * operator->() ENTT_NOEXCEPT {
+    [[nodiscard]] Resource * operator->() ENTT_NOEXCEPT {
         return const_cast<Resource *>(std::as_const(*this).operator->());
     }
 
@@ -93,7 +93,7 @@ public:
      * @brief Returns true if a handle contains a resource, false otherwise.
      * @return True if the handle contains a resource, false otherwise.
      */
-    explicit operator bool() const ENTT_NOEXCEPT {
+    [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
         return static_cast<bool>(resource);
     }
 

+ 1 - 1
src/entt/resource/loader.hpp

@@ -53,7 +53,7 @@ class loader {
      * @return The resource just loaded or an empty pointer in case of errors.
      */
     template<typename... Args>
-    std::shared_ptr<Resource> get(Args &&... args) const {
+    [[nodiscard]] std::shared_ptr<Resource> get(Args &&... args) const {
         return static_cast<const Loader *>(this)->load(std::forward<Args>(args)...);
     }
 };