diff options
| author | Mai <mathew1800@gmail.com> | 2022-10-26 15:12:48 +0000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-26 15:12:48 +0000 | 
| commit | 041eb5bf57f4db8609341c77bd5d38ddcd8b2d80 (patch) | |
| tree | f8df340674b1480f3e0f53a9d21b7fa6fbb350f3 /src/common | |
| parent | d8e3380ea529daf3b57b8bb5a4e97baa69a5dfad (diff) | |
| parent | 8b4d5aeb4f01348312ca38555d7951ff54b23fc3 (diff) | |
Merge pull request #9131 from Morph1984/contiguous
concepts: Use the std::contiguous_iterator concept
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/concepts.h | 16 | ||||
| -rw-r--r-- | src/common/fs/file.h | 12 | 
2 files changed, 9 insertions, 19 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 @@  #pragma once +#include <iterator>  #include <type_traits>  namespace Common { -// Check if type is like an STL container +// Check if type satisfies the ContiguousContainer named requirement.  template <typename T> -concept IsSTLContainer = requires(T t) { -    typename T::value_type; -    typename T::iterator; -    typename T::const_iterator; -    // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it. -    t.begin(); -    t.end(); -    t.cbegin(); -    t.cend(); -    t.data(); -    t.size(); -}; +concept IsContiguousContainer = std::contiguous_iterator<typename T::iterator>;  // TODO: Replace with std::derived_from when the <concepts> header  //       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:      /**       * Helper function which deduces the value type of a contiguous STL container used in ReadSpan. -     * If T is not a contiguous STL container as defined by the concept IsSTLContainer, this calls -     * ReadObject and T must be a trivially copyable object. +     * If T is not a contiguous container as defined by the concept IsContiguousContainer, this +     * calls ReadObject and T must be a trivially copyable object.       *       * See ReadSpan for more details if T is a contiguous container.       * See ReadObject for more details if T is a trivially copyable object. @@ -223,7 +223,7 @@ public:       */      template <typename T>      [[nodiscard]] size_t Read(T& data) const { -        if constexpr (IsSTLContainer<T>) { +        if constexpr (IsContiguousContainer<T>) {              using ContiguousType = typename T::value_type;              static_assert(std::is_trivially_copyable_v<ContiguousType>,                            "Data type must be trivially copyable."); @@ -235,8 +235,8 @@ public:      /**       * Helper function which deduces the value type of a contiguous STL container used in WriteSpan. -     * If T is not a contiguous STL container as defined by the concept IsSTLContainer, this calls -     * WriteObject and T must be a trivially copyable object. +     * If T is not a contiguous STL container as defined by the concept IsContiguousContainer, this +     * calls WriteObject and T must be a trivially copyable object.       *       * See WriteSpan for more details if T is a contiguous container.       * See WriteObject for more details if T is a trivially copyable object. @@ -249,7 +249,7 @@ public:       */      template <typename T>      [[nodiscard]] size_t Write(const T& data) const { -        if constexpr (IsSTLContainer<T>) { +        if constexpr (IsContiguousContainer<T>) {              using ContiguousType = typename T::value_type;              static_assert(std::is_trivially_copyable_v<ContiguousType>,                            "Data type must be trivially copyable."); | 
