Browse Source

view/group: raw() isn't bound to pointer types

Michele Caini 5 years ago
parent
commit
e8f982e909
3 changed files with 13 additions and 17 deletions
  1. 6 6
      src/entt/entity/group.hpp
  2. 5 6
      src/entt/entity/view.hpp
  3. 2 5
      test/entt/entity/view.cpp

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

@@ -681,11 +681,11 @@ public:
     }
 
     /**
-     * @brief Direct access to the list of components of a given pool.
+     * @brief Direct access to the raw representation offered by the storage.
      *
-     * The returned pointer is such that range
-     * `[raw<Component>(), raw<Component>() + size())` is always a valid range,
-     * even if the container is empty.<br/>
+     * For fully contiguous storage classes, the returned pointer is such that
+     * range `[raw<Component>(), raw<Component>() + size())` is always a valid
+     * range, even if the container is empty.
      *
      * @warning
      * This function is only available for owned types.
@@ -694,10 +694,10 @@ public:
      * @return A pointer to the array of components.
      */
     template<typename Component>
-    [[nodiscard]] Component * raw() const ENTT_NOEXCEPT {
+    [[nodiscard]] auto raw() const ENTT_NOEXCEPT {
         static_assert((std::is_same_v<Component, Owned> || ...), "Non-owned type");
         auto *cpool = std::get<storage_type<Component> *>(pools);
-        return cpool ? cpool->raw() : nullptr;
+        return cpool ? cpool->raw() : decltype(cpool->raw()){};
     }
 
     /**

+ 5 - 6
src/entt/entity/view.hpp

@@ -668,8 +668,6 @@ class basic_view<Entity, exclude_t<>, Component> final {
     };
 
 public:
-    /*! @brief Type of component iterated by the view. */
-    using raw_type = Component;
     /*! @brief Underlying entity identifier. */
     using entity_type = Entity;
     /*! @brief Unsigned integer type. */
@@ -711,14 +709,15 @@ public:
     }
 
     /**
-     * @brief Direct access to the list of components.
+     * @brief Direct access to the raw representation offered by the storage.
      *
-     * The returned pointer is such that range `[raw(), raw() + size())` is
-     * always a valid range, even if the container is empty.
+     * For fully contiguous storage classes, the returned pointer is such that
+     * range `[raw<Component>(), raw<Component>() + size())` is always a valid
+     * range, even if the container is empty.
      *
      * @return A pointer to the array of components.
      */
-    [[nodiscard]] raw_type * raw() const ENTT_NOEXCEPT {
+    [[nodiscard]] auto raw() const ENTT_NOEXCEPT {
         return std::get<0>(pools)->raw();
     }
 

+ 2 - 5
test/entt/entity/view.cpp

@@ -226,8 +226,8 @@ TEST(SingleComponentView, ConstNonConstAndAllInBetween) {
     ASSERT_EQ(view.size(), 1u);
     ASSERT_EQ(cview.size(), 1u);
 
-    static_assert(std::is_same_v<typename decltype(view)::raw_type, int>);
-    static_assert(std::is_same_v<typename decltype(cview)::raw_type, const int>);
+    static_assert(std::is_same_v<decltype(view.raw()), int *>);
+    static_assert(std::is_same_v<decltype(cview.raw()), const int *>);
 
     static_assert(std::is_same_v<decltype(view.get<int>({})), int &>);
     static_assert(std::is_same_v<decltype(view.get({})), std::tuple<int &>>);
@@ -268,9 +268,6 @@ TEST(SingleComponentView, ConstNonConstAndAllInBetweenWithEmptyType) {
     ASSERT_EQ(view.size(), 1u);
     ASSERT_EQ(cview.size(), 1u);
 
-    static_assert(std::is_same_v<typename decltype(view)::raw_type, empty_type>);
-    static_assert(std::is_same_v<typename decltype(cview)::raw_type, const empty_type>);
-
     static_assert(std::is_same_v<decltype(view.get({})), std::tuple<>>);
     static_assert(std::is_same_v<decltype(cview.get({})), std::tuple<>>);