diff options
| -rw-r--r-- | src/common/concepts.h | 16 | ||||
| -rw-r--r-- | src/common/fs/file.h | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.h | 2 |
3 files changed, 10 insertions, 20 deletions
diff --git a/src/common/concepts.h b/src/common/concepts.h index e8ce30dfe..a9acff3e7 100644 --- a/src/common/concepts.h +++ b/src/common/concepts.h | |||
| @@ -3,24 +3,14 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <iterator> | ||
| 6 | #include <type_traits> | 7 | #include <type_traits> |
| 7 | 8 | ||
| 8 | namespace Common { | 9 | namespace Common { |
| 9 | 10 | ||
| 10 | // Check if type is like an STL container | 11 | // Check if type satisfies the ContiguousContainer named requirement. |
| 11 | template <typename T> | 12 | template <typename T> |
| 12 | concept IsSTLContainer = requires(T t) { | 13 | concept IsContiguousContainer = std::contiguous_iterator<typename T::iterator>; |
| 13 | typename T::value_type; | ||
| 14 | typename T::iterator; | ||
| 15 | typename T::const_iterator; | ||
| 16 | // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it. | ||
| 17 | t.begin(); | ||
| 18 | t.end(); | ||
| 19 | t.cbegin(); | ||
| 20 | t.cend(); | ||
| 21 | t.data(); | ||
| 22 | t.size(); | ||
| 23 | }; | ||
| 24 | 14 | ||
| 25 | // TODO: Replace with std::derived_from when the <concepts> header | 15 | // TODO: Replace with std::derived_from when the <concepts> header |
| 26 | // is available on all supported platforms. | 16 | // is available on all supported platforms. |
diff --git a/src/common/fs/file.h b/src/common/fs/file.h index 69b53384c..167c4d826 100644 --- a/src/common/fs/file.h +++ b/src/common/fs/file.h | |||
| @@ -209,8 +209,8 @@ public: | |||
| 209 | 209 | ||
| 210 | /** | 210 | /** |
| 211 | * Helper function which deduces the value type of a contiguous STL container used in ReadSpan. | 211 | * Helper function which deduces the value type of a contiguous STL container used in ReadSpan. |
| 212 | * If T is not a contiguous STL container as defined by the concept IsSTLContainer, this calls | 212 | * If T is not a contiguous container as defined by the concept IsContiguousContainer, this |
| 213 | * ReadObject and T must be a trivially copyable object. | 213 | * calls ReadObject and T must be a trivially copyable object. |
| 214 | * | 214 | * |
| 215 | * See ReadSpan for more details if T is a contiguous container. | 215 | * See ReadSpan for more details if T is a contiguous container. |
| 216 | * See ReadObject for more details if T is a trivially copyable object. | 216 | * See ReadObject for more details if T is a trivially copyable object. |
| @@ -223,7 +223,7 @@ public: | |||
| 223 | */ | 223 | */ |
| 224 | template <typename T> | 224 | template <typename T> |
| 225 | [[nodiscard]] size_t Read(T& data) const { | 225 | [[nodiscard]] size_t Read(T& data) const { |
| 226 | if constexpr (IsSTLContainer<T>) { | 226 | if constexpr (IsContiguousContainer<T>) { |
| 227 | using ContiguousType = typename T::value_type; | 227 | using ContiguousType = typename T::value_type; |
| 228 | static_assert(std::is_trivially_copyable_v<ContiguousType>, | 228 | static_assert(std::is_trivially_copyable_v<ContiguousType>, |
| 229 | "Data type must be trivially copyable."); | 229 | "Data type must be trivially copyable."); |
| @@ -235,8 +235,8 @@ public: | |||
| 235 | 235 | ||
| 236 | /** | 236 | /** |
| 237 | * Helper function which deduces the value type of a contiguous STL container used in WriteSpan. | 237 | * Helper function which deduces the value type of a contiguous STL container used in WriteSpan. |
| 238 | * If T is not a contiguous STL container as defined by the concept IsSTLContainer, this calls | 238 | * If T is not a contiguous STL container as defined by the concept IsContiguousContainer, this |
| 239 | * WriteObject and T must be a trivially copyable object. | 239 | * calls WriteObject and T must be a trivially copyable object. |
| 240 | * | 240 | * |
| 241 | * See WriteSpan for more details if T is a contiguous container. | 241 | * See WriteSpan for more details if T is a contiguous container. |
| 242 | * See WriteObject for more details if T is a trivially copyable object. | 242 | * See WriteObject for more details if T is a trivially copyable object. |
| @@ -249,7 +249,7 @@ public: | |||
| 249 | */ | 249 | */ |
| 250 | template <typename T> | 250 | template <typename T> |
| 251 | [[nodiscard]] size_t Write(const T& data) const { | 251 | [[nodiscard]] size_t Write(const T& data) const { |
| 252 | if constexpr (IsSTLContainer<T>) { | 252 | if constexpr (IsContiguousContainer<T>) { |
| 253 | using ContiguousType = typename T::value_type; | 253 | using ContiguousType = typename T::value_type; |
| 254 | static_assert(std::is_trivially_copyable_v<ContiguousType>, | 254 | static_assert(std::is_trivially_copyable_v<ContiguousType>, |
| 255 | "Data type must be trivially copyable."); | 255 | "Data type must be trivially copyable."); |
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index a0522bca0..1083638a9 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h | |||
| @@ -304,7 +304,7 @@ public: | |||
| 304 | */ | 304 | */ |
| 305 | template <typename T, typename = std::enable_if_t<!std::is_pointer_v<T>>> | 305 | template <typename T, typename = std::enable_if_t<!std::is_pointer_v<T>>> |
| 306 | std::size_t WriteBuffer(const T& data, std::size_t buffer_index = 0) const { | 306 | std::size_t WriteBuffer(const T& data, std::size_t buffer_index = 0) const { |
| 307 | if constexpr (Common::IsSTLContainer<T>) { | 307 | if constexpr (Common::IsContiguousContainer<T>) { |
| 308 | using ContiguousType = typename T::value_type; | 308 | using ContiguousType = typename T::value_type; |
| 309 | static_assert(std::is_trivially_copyable_v<ContiguousType>, | 309 | static_assert(std::is_trivially_copyable_v<ContiguousType>, |
| 310 | "Container to WriteBuffer must contain trivially copyable objects"); | 310 | "Container to WriteBuffer must contain trivially copyable objects"); |