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

DPL: use requires rather than enable_if / static_assert #13832

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Framework/Core/include/Framework/ServiceRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,33 +267,32 @@ struct ServiceRegistry {

/// @deprecated old API to be substituted with the ServiceHandle one
template <class I, class C, enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void registerService(C* service, Salt salt = ServiceRegistry::globalDeviceSalt())
{
// This only works for concrete implementations of the type T.
// We need type elision as we do not want to know all the services in
// advance
static_assert(std::is_base_of<I, C>::value == true,
"Registered service is not derived from declared interface");
constexpr ServiceTypeHash typeHash{TypeIdHelpers::uniqueId<I>()};
ServiceRegistry::registerService(typeHash, reinterpret_cast<void*>(service), K, salt, typeid(C).name());
}

/// @deprecated old API to be substituted with the ServiceHandle one
template <class I, class C, enum ServiceKind K = ServiceKind::Serial>
requires std::is_base_of_v<I, C>
void registerService(C const* service, Salt salt = ServiceRegistry::globalDeviceSalt())
{
// This only works for concrete implementations of the type T.
// We need type elision as we do not want to know all the services in
// advance
static_assert(std::is_base_of<I, C>::value == true,
"Registered service is not derived from declared interface");
constexpr ServiceTypeHash typeHash{TypeIdHelpers::uniqueId<I const>()};
this->registerService(typeHash, reinterpret_cast<void*>(const_cast<C*>(service)), K, salt, typeid(C).name());
}

/// Check if service of type T is currently active.
template <typename T>
std::enable_if_t<std::is_const_v<T> == false, bool> active(Salt salt) const
requires(std::is_const_v<T> == false)
bool active(Salt salt) const
{
constexpr ServiceTypeHash typeHash{TypeIdHelpers::uniqueId<T>()};
if (this->getPos(typeHash, GLOBAL_CONTEXT_SALT) != -1) {
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/include/Framework/ServiceRegistryRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class ServiceRegistryRef

/// Check if service of type T is currently active.
template <typename T>
std::enable_if_t<std::is_const_v<T> == false, bool> active() const
requires(std::is_const_v<T> == false)
[[nodiscard]] bool active() const
{
return mRegistry.active<T>(mSalt);
}
Expand Down
Loading