Просмотр исходного кода

stl: add string_view.hpp and replace std::string_view

skypjack 1 день назад
Родитель
Сommit
a5c0595896
5 измененных файлов с 32 добавлено и 16 удалено
  1. 1 0
      CMakeLists.txt
  2. 9 9
      src/entt/core/type_info.hpp
  3. 1 0
      src/entt/entt.hpp
  4. 7 7
      src/entt/meta/meta.hpp
  5. 14 0
      src/entt/stl/string_view.hpp

+ 1 - 0
CMakeLists.txt

@@ -207,6 +207,7 @@ if(ENTT_INCLUDE_HEADERS)
         stl/limits.hpp
         stl/limits.hpp
         stl/memory.hpp
         stl/memory.hpp
         stl/string.hpp
         stl/string.hpp
+        stl/string_view.hpp
         stl/tuple.hpp
         stl/tuple.hpp
         stl/type_traits.hpp
         stl/type_traits.hpp
         stl/utility.hpp
         stl/utility.hpp

+ 9 - 9
src/entt/core/type_info.hpp

@@ -2,8 +2,8 @@
 #define ENTT_CORE_TYPE_INFO_HPP
 #define ENTT_CORE_TYPE_INFO_HPP
 
 
 #include <compare>
 #include <compare>
-#include <string_view>
 #include "../config/config.h"
 #include "../config/config.h"
+#include "../stl/string_view.hpp"
 #include "../stl/type_traits.hpp"
 #include "../stl/type_traits.hpp"
 #include "../stl/utility.hpp"
 #include "../stl/utility.hpp"
 #include "fwd.hpp"
 #include "fwd.hpp"
@@ -33,23 +33,23 @@ template<typename Type>
 template<typename Type>
 template<typename Type>
 [[nodiscard]] constexpr auto stripped_type_name() noexcept {
 [[nodiscard]] constexpr auto stripped_type_name() noexcept {
 #if defined ENTT_PRETTY_FUNCTION
 #if defined ENTT_PRETTY_FUNCTION
-    const std::string_view full_name{pretty_function<Type>()};
+    const stl::string_view full_name{pretty_function<Type>()};
     auto first = full_name.find_first_not_of(' ', full_name.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
     auto first = full_name.find_first_not_of(' ', full_name.find_first_of(ENTT_PRETTY_FUNCTION_PREFIX) + 1);
     auto value = full_name.substr(first, full_name.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
     auto value = full_name.substr(first, full_name.find_last_of(ENTT_PRETTY_FUNCTION_SUFFIX) - first);
     return value;
     return value;
 #else
 #else
-    return std::string_view{};
+    return stl::string_view{};
 #endif
 #endif
 }
 }
 
 
 template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
 template<typename Type, auto = stripped_type_name<Type>().find_first_of('.')>
-[[nodiscard]] ENTT_CONSTEVAL std::string_view type_name(int) noexcept {
+[[nodiscard]] ENTT_CONSTEVAL stl::string_view type_name(int) noexcept {
     constexpr auto value = stripped_type_name<Type>();
     constexpr auto value = stripped_type_name<Type>();
     return value;
     return value;
 }
 }
 
 
 template<typename Type>
 template<typename Type>
-[[nodiscard]] std::string_view type_name(char) noexcept {
+[[nodiscard]] stl::string_view type_name(char) noexcept {
     static const auto value = stripped_type_name<Type>();
     static const auto value = stripped_type_name<Type>();
     return value;
     return value;
 }
 }
@@ -128,12 +128,12 @@ struct type_name final {
      * @brief Returns the name of a given type.
      * @brief Returns the name of a given type.
      * @return The name of the given type.
      * @return The name of the given type.
      */
      */
-    [[nodiscard]] static constexpr std::string_view value() noexcept {
+    [[nodiscard]] static constexpr stl::string_view value() noexcept {
         return internal::type_name<Type>(0);
         return internal::type_name<Type>(0);
     }
     }
 
 
     /*! @copydoc value */
     /*! @copydoc value */
-    [[nodiscard]] constexpr operator std::string_view() const noexcept {
+    [[nodiscard]] constexpr operator stl::string_view() const noexcept {
         return value();
         return value();
     }
     }
 };
 };
@@ -172,7 +172,7 @@ struct type_info final {
      * @brief Type name.
      * @brief Type name.
      * @return Type name.
      * @return Type name.
      */
      */
-    [[nodiscard]] constexpr std::string_view name() const noexcept {
+    [[nodiscard]] constexpr stl::string_view name() const noexcept {
         return alias;
         return alias;
     }
     }
 
 
@@ -197,7 +197,7 @@ struct type_info final {
 private:
 private:
     id_type seq;
     id_type seq;
     id_type identifier;
     id_type identifier;
-    std::string_view alias;
+    stl::string_view alias;
 };
 };
 
 
 /**
 /**

+ 1 - 0
src/entt/entt.hpp

@@ -81,6 +81,7 @@ namespace entt::stl {}
 #include "stl/limits.hpp"
 #include "stl/limits.hpp"
 #include "stl/memory.hpp"
 #include "stl/memory.hpp"
 #include "stl/string.hpp"
 #include "stl/string.hpp"
+#include "stl/string_view.hpp"
 #include "stl/tuple.hpp"
 #include "stl/tuple.hpp"
 #include "stl/type_traits.hpp"
 #include "stl/type_traits.hpp"
 #include "stl/utility.hpp"
 #include "stl/utility.hpp"

+ 7 - 7
src/entt/meta/meta.hpp

@@ -3,7 +3,6 @@
 
 
 #include <concepts>
 #include <concepts>
 #include <memory>
 #include <memory>
-#include <string_view>
 #include "../config/config.h"
 #include "../config/config.h"
 #include "../core/any.hpp"
 #include "../core/any.hpp"
 #include "../core/concepts.hpp"
 #include "../core/concepts.hpp"
@@ -16,6 +15,7 @@
 #include "../stl/array.hpp"
 #include "../stl/array.hpp"
 #include "../stl/cstddef.hpp"
 #include "../stl/cstddef.hpp"
 #include "../stl/iterator.hpp"
 #include "../stl/iterator.hpp"
+#include "../stl/string_view.hpp"
 #include "../stl/type_traits.hpp"
 #include "../stl/type_traits.hpp"
 #include "../stl/utility.hpp"
 #include "../stl/utility.hpp"
 #include "adl_pointer.hpp"
 #include "adl_pointer.hpp"
@@ -856,8 +856,8 @@ struct meta_data: meta_object<internal::meta_data_node> {
      * @brief Returns the name assigned to a data member, if any.
      * @brief Returns the name assigned to a data member, if any.
      * @return The name assigned to the data member, if any.
      * @return The name assigned to the data member, if any.
      */
      */
-    [[nodiscard]] std::string_view name() const noexcept {
-        return (node_or_assert().name == nullptr) ? std::string_view{} : std::string_view{node_or_assert().name};
+    [[nodiscard]] stl::string_view name() const noexcept {
+        return (node_or_assert().name == nullptr) ? stl::string_view{} : stl::string_view{node_or_assert().name};
     }
     }
 
 
     /**
     /**
@@ -949,8 +949,8 @@ struct meta_func: meta_object<internal::meta_func_node> {
      * @brief Returns the name assigned to a member function, if any.
      * @brief Returns the name assigned to a member function, if any.
      * @return The name assigned to the member function, if any.
      * @return The name assigned to the member function, if any.
      */
      */
-    [[nodiscard]] std::string_view name() const noexcept {
-        return (node_or_assert().name == nullptr) ? std::string_view{} : std::string_view{node_or_assert().name};
+    [[nodiscard]] stl::string_view name() const noexcept {
+        return (node_or_assert().name == nullptr) ? stl::string_view{} : stl::string_view{node_or_assert().name};
     }
     }
 
 
     /**
     /**
@@ -1140,8 +1140,8 @@ public:
      * @brief Returns the name assigned to a type, if any.
      * @brief Returns the name assigned to a type, if any.
      * @return The name assigned to the type, if any.
      * @return The name assigned to the type, if any.
      */
      */
-    [[nodiscard]] std::string_view name() const noexcept {
-        return (fetch_node().name == nullptr) ? std::string_view{} : std::string_view{fetch_node().name};
+    [[nodiscard]] stl::string_view name() const noexcept {
+        return (fetch_node().name == nullptr) ? stl::string_view{} : stl::string_view{fetch_node().name};
     }
     }
 
 
     /**
     /**

+ 14 - 0
src/entt/stl/string_view.hpp

@@ -0,0 +1,14 @@
+#ifndef ENTT_STL_STRING_VIEW_HPP
+#define ENTT_STL_STRING_VIEW_HPP
+
+#include <string_view>
+
+/*! @cond ENTT_INTERNAL */
+namespace entt::stl {
+
+using std::string_view;
+
+} // namespace entt::stl
+/*! @endcond */
+
+#endif