Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use concepts instead of std::enable_if #16758

Merged
merged 3 commits into from
Feb 26, 2025
Merged

use concepts instead of std::enable_if #16758

merged 3 commits into from
Feb 26, 2025

Conversation

oltolm
Copy link
Contributor

@oltolm oltolm commented Feb 24, 2025

I was learning C++ concepts and decided to replace usages of std::enable_if and std::void_t with concepts.

@@ -18,9 +18,8 @@ namespace utils
};

template <typename T>
concept Bitcopy = (std::is_arithmetic_v<T>) || (std::is_enum_v<T>) || Integral<T> || requires ()
{
std::enable_if_t<std::conjunction_v<typename T::enable_bitcopy>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is wrong, enable_if_t checks three things here:

  1. enable_bitcopy exists.
  2. enable_bitcopy is constexpr.
  3. enable_bitcopy::operator()() is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -30,7 +29,7 @@ namespace utils
};

template <typename T>
concept ListAlike = requires (std::remove_cvref_t<T>& obj) { obj.insert(obj.end(), std::declval<typename T::value_type>()); };
concept ListAlike = requires(std::remove_cvref_t<T>& obj, T::value_type item) { obj.insert(obj.end(), item); };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
concept ListAlike = requires(std::remove_cvref_t<T>& obj, T::value_type item) { obj.insert(obj.end(), item); };
concept ListAlike = requires(std::remove_cvref_t<T>& obj, T::value_type item) { obj.insert(obj.end(), std::move(item)); };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixed

{
return error.empty();
}
operator bool() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is correct now, it was using spaces before. Some lines in the file use spaces others tabs.

@Megamouse Megamouse added the Refactoring Refactors or simplifies existing code label Feb 25, 2025
@elad335 elad335 merged commit 29ad4ec into RPCS3:master Feb 26, 2025
12 checks passed
@oltolm oltolm deleted the concepts branch February 26, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Refactors or simplifies existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants