Skip to content

use concepts instead of std::enable_if#16758

Merged
elad335 merged 3 commits into
RPCS3:masterfrom
oltolm:concepts
Feb 26, 2025
Merged

use concepts instead of std::enable_if#16758
elad335 merged 3 commits into
RPCS3:masterfrom
oltolm:concepts

Conversation

@oltolm
Copy link
Copy Markdown
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.

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread rpcs3/util/serialization.hpp Outdated

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indentation

Copy link
Copy Markdown
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
@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