concepts.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <iterator>
  5. #include <type_traits>
  6. namespace Common {
  7. // Check if type satisfies the ContiguousContainer named requirement.
  8. template <typename T>
  9. concept IsContiguousContainer = std::contiguous_iterator<typename T::iterator>;
  10. // TODO: Replace with std::derived_from when the <concepts> header
  11. // is available on all supported platforms.
  12. template <typename Derived, typename Base>
  13. concept DerivedFrom = requires {
  14. std::is_base_of_v<Base, Derived>;
  15. std::is_convertible_v<const volatile Derived*, const volatile Base*>;
  16. };
  17. // TODO: Replace with std::convertible_to when libc++ implements it.
  18. template <typename From, typename To>
  19. concept ConvertibleTo = std::is_convertible_v<From, To>;
  20. // No equivalents in the stdlib
  21. template <typename T>
  22. concept IsArithmetic = std::is_arithmetic_v<T>;
  23. template <typename T>
  24. concept IsIntegral = std::is_integral_v<T>;
  25. } // namespace Common