concepts.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2020 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <type_traits>
  6. namespace Common {
  7. // Check if type is like an STL container
  8. template <typename T>
  9. concept IsSTLContainer = requires(T t) {
  10. typename T::value_type;
  11. typename T::iterator;
  12. typename T::const_iterator;
  13. // TODO(ogniK): Replace below is std::same_as<void> when MSVC supports it.
  14. t.begin();
  15. t.end();
  16. t.cbegin();
  17. t.cend();
  18. t.data();
  19. t.size();
  20. };
  21. // TODO: Replace with std::derived_from when the <concepts> header
  22. // is available on all supported platforms.
  23. template <typename Derived, typename Base>
  24. concept DerivedFrom = requires {
  25. std::is_base_of_v<Base, Derived>;
  26. std::is_convertible_v<const volatile Derived*, const volatile Base*>;
  27. };
  28. // TODO: Replace with std::convertible_to when libc++ implements it.
  29. template <typename From, typename To>
  30. concept ConvertibleTo = std::is_convertible_v<From, To>;
  31. } // namespace Common