Skip to content

Commit

Permalink
DPL: use requires rather than enable_if / static_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Jan 4, 2025
1 parent f5d37d2 commit 64dd90c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit 64dd90c

Please sign in to comment.