diff options
Diffstat (limited to 'src/common/concepts.h')
| -rw-r--r-- | src/common/concepts.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/concepts.h b/src/common/concepts.h new file mode 100644 index 000000000..54252e778 --- /dev/null +++ b/src/common/concepts.h | |||
| @@ -0,0 +1,34 @@ | |||
| 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 | // TODO: Replace with std::derived_from when the <concepts> header | ||
| 27 | // is available on all supported platforms. | ||
| 28 | template <typename Derived, typename Base> | ||
| 29 | concept DerivedFrom = requires { | ||
| 30 | std::is_base_of_v<Base, Derived>; | ||
| 31 | std::is_convertible_v<const volatile Derived*, const volatile Base*>; | ||
| 32 | }; | ||
| 33 | |||
| 34 | } // namespace Common | ||