Skip to content

Commit 35d25a7

Browse files
committed
Container/MeshNodePtr: Default constructible
1 parent 850e666 commit 35d25a7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

modules/Container/MeshNetwork.mpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,15 @@ export namespace CppUtils::Container
163163
return MeshNodePtr{NetworkPtr::make(std::forward<decltype(args)>(args)...)};
164164
}
165165

166+
MeshNodePtr() = default;
166167
MeshNodePtr(const SharedPtr& node): m_node(node) {}
167168
MeshNodePtr(SharedPtr&& node): m_node(std::move(node)) {}
168169

170+
explicit operator bool() const noexcept
171+
{
172+
return m_node != nullptr;
173+
}
174+
169175
[[nodiscard]] auto operator[](const Key& key) -> Branch
170176
{
171177
return Branch{m_node, key};
@@ -187,6 +193,6 @@ export namespace CppUtils::Container
187193
}
188194

189195
private:
190-
SharedPtr m_node;
196+
SharedPtr m_node = nullptr;
191197
};
192198
}

tests/Container/MeshNetwork.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export namespace CppUtils::UnitTest::Container::MeshNetwork
2323
});
2424

2525
suite.addTest("Copy reference", [&] {
26-
auto appleRef = std::optional<StringMeshNodePtr>{};
26+
StringMeshNodePtr appleRef;
2727
{
2828
auto apple = StringMeshNodePtr::make("apple");
2929
appleRef = apple;
3030
}
31-
auto accessor = (*appleRef)->sharedAccess();
31+
auto accessor = appleRef->sharedAccess();
3232
const auto& value = accessor->value.value;
3333
Logger::print("{}\n", value);
3434
suite.expectEqual(value, "apple");

0 commit comments

Comments
 (0)