Added ability to provide not_null to CreateChild function.
This commit is contained in:
parent
69e474ea77
commit
6d1014fa8f
1 changed files with 12 additions and 7 deletions
|
|
@ -56,16 +56,21 @@ inline base::unique_qptr<Widget> CreateObject(Args &&...args) {
|
||||||
|
|
||||||
template <typename Value, typename Parent, typename ...Args>
|
template <typename Value, typename Parent, typename ...Args>
|
||||||
inline Value *CreateChild(
|
inline Value *CreateChild(
|
||||||
Parent *parent,
|
Parent parent,
|
||||||
Args &&...args) {
|
Args &&...args) {
|
||||||
Expects(parent != nullptr);
|
if constexpr (std::is_pointer_v<Parent>) {
|
||||||
|
Expects(parent != nullptr);
|
||||||
|
|
||||||
if constexpr (std::is_base_of_v<QObject, Value>) {
|
if constexpr (std::is_base_of_v<QObject, Value>) {
|
||||||
return new Value(parent, std::forward<Args>(args)...);
|
return new Value(parent, std::forward<Args>(args)...);
|
||||||
|
} else {
|
||||||
|
return CreateChild<details::AttachmentOwner<Value>>(
|
||||||
|
parent,
|
||||||
|
std::forward<Args>(args)...)->value();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return CreateChild<details::AttachmentOwner<Value>>(
|
static_assert(requires(const Parent &t) { t.get(); });
|
||||||
parent,
|
return new Value(parent.get(), std::forward<Args>(args)...);
|
||||||
std::forward<Args>(args)...)->value();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue