concepts.h 1.0 KB

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