Skip to content

Commit 64dd90c

Browse files
committed
DPL: use requires rather than enable_if / static_assert
1 parent f5d37d2 commit 64dd90c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Framework/Core/include/Framework/ServiceRegistry.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,33 +267,32 @@ struct ServiceRegistry {
267267

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

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

294292
/// Check if service of type T is currently active.
295293
template <typename T>
296-
std::enable_if_t<std::is_const_v<T> == false, bool> active(Salt salt) const
294+
requires(std::is_const_v<T> == false)
295+
bool active(Salt salt) const
297296
{
298297
constexpr ServiceTypeHash typeHash{TypeIdHelpers::uniqueId<T>()};
299298
if (this->getPos(typeHash, GLOBAL_CONTEXT_SALT) != -1) {

Framework/Core/include/Framework/ServiceRegistryRef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class ServiceRegistryRef
7272

7373
/// Check if service of type T is currently active.
7474
template <typename T>
75-
std::enable_if_t<std::is_const_v<T> == false, bool> active() const
75+
requires(std::is_const_v<T> == false)
76+
[[nodiscard]] bool active() const
7677
{
7778
return mRegistry.active<T>(mSalt);
7879
}

0 commit comments

Comments
 (0)