diff options
| author | 2020-08-03 21:28:54 +1000 | |
|---|---|---|
| committer | 2020-08-03 07:28:54 -0400 | |
| commit | 9b75481755c8d566bc666465d659115bba2b2578 (patch) | |
| tree | 309d0ff37c8e68d178b65861abeb3bb0e8387f43 /src/common/concepts.h | |
| parent | Merge pull request #4263 from lat9nq/fix-screencaps-2 (diff) | |
| download | yuzu-9b75481755c8d566bc666465d659115bba2b2578.tar.gz yuzu-9b75481755c8d566bc666465d659115bba2b2578.tar.xz yuzu-9b75481755c8d566bc666465d659115bba2b2578.zip | |
ipc: Allow all trivially copyable objects to be passed directly into WriteBuffer (#4465)
* ipc: Allow all trivially copyable objects to be passed directly into WriteBuffer
With the support of C++20, we can use concepts to deduce if a type is an STL container or not.
* More agressive concept for stl containers
* Add -fconcepts
* Move to common namespace
* Add Common::IsBaseOf
Diffstat (limited to 'src/common/concepts.h')
| -rw-r--r-- | src/common/concepts.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/common/concepts.h b/src/common/concepts.h new file mode 100644 index 000000000..db5fb373d --- /dev/null +++ b/src/common/concepts.h | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | // Copyright 2020 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | namespace Common { | ||
| 8 | |||
| 9 | #include <type_traits> | ||
| 10 | |||
| 11 | // Check if type is like an STL container | ||
| 12 | template <typename T> | ||
| 13 | concept IsSTLContainer = requires(T t) { | ||
| 14 | typename T::value_type; | ||
| 15 | typename T::iterator; | ||
| 16 | typename T::const_iterator; | ||
| 17 | // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it. | ||
| 18 | t.begin(); | ||
| 19 | t.end(); | ||
| 20 | t.cbegin(); | ||
| 21 | t.cend(); | ||
| 22 | t.data(); | ||
| 23 | t.size(); | ||
| 24 | }; | ||
| 25 | |||
| 26 | // Check if type T is derived from T2 | ||
| 27 | template <typename T, typename T2> | ||
| 28 | concept IsBaseOf = requires { | ||
| 29 | std::is_base_of_v<T, T2>; | ||
| 30 | }; | ||
| 31 | |||
| 32 | } // namespace Common | ||