Added ability to provide not_null to CreateChild function.

This commit is contained in:
23rd 2024-04-25 17:32:29 +03:00
parent 69e474ea77
commit 6d1014fa8f

View file

@ -56,8 +56,9 @@ inline base::unique_qptr<Widget> CreateObject(Args &&...args) {
template <typename Value, typename Parent, typename ...Args>
inline Value *CreateChild(
Parent *parent,
Parent parent,
Args &&...args) {
if constexpr (std::is_pointer_v<Parent>) {
Expects(parent != nullptr);
if constexpr (std::is_base_of_v<QObject, Value>) {
@ -67,6 +68,10 @@ inline Value *CreateChild(
parent,
std::forward<Args>(args)...)->value();
}
} else {
static_assert(requires(const Parent &t) { t.get(); });
return new Value(parent.get(), std::forward<Args>(args)...);
}
}
template <typename Value>