File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -264,6 +264,16 @@ export namespace CppUtils::Container
264264 return std::unexpected{"Failed to lock weak pointer for branch. Node might have been deleted"sv};
265265 }
266266
267+ [[nodiscard]] auto front() const -> std::expected<MeshNodePtr, std::string_view>
268+ {
269+ return (*this)[0];
270+ }
271+
272+ [[nodiscard]] auto back() const -> std::expected<MeshNodePtr, std::string_view>
273+ {
274+ return (*this)[std::size(m_children) - 1];
275+ }
276+
267277 private:
268278 NodePtrType& m_self;
269279 const Key& m_key;
Original file line number Diff line number Diff line change @@ -574,5 +574,31 @@ export namespace CppUtils::UnitTest::Container::MeshNetwork
574574 auto _ = invalidNode.at("Branch");
575575 });
576576 });
577+
578+ suite.addTest("Get first node", [&] {
579+ auto root = StringMeshNodePtr::makeRoot("root");
580+ auto child1 = StringMeshNodePtr::make("child1");
581+ auto child2 = StringMeshNodePtr::make("child2");
582+ root["Branch"] >> child1;
583+ root["Branch"] >> child2;
584+
585+ auto childExpected = root["Branch"].front();
586+
587+ suite.expect(childExpected.has_value());
588+ suite.expectEqual(childExpected.value().getValue().value(), "child1");
589+ });
590+
591+ suite.addTest("Get last node", [&] {
592+ auto root = StringMeshNodePtr::makeRoot("root");
593+ auto child1 = StringMeshNodePtr::make("child1");
594+ auto child2 = StringMeshNodePtr::make("child2");
595+ root["Branch"] >> child1;
596+ root["Branch"] >> child2;
597+
598+ auto childExpected = root["Branch"].back();
599+
600+ suite.expect(childExpected.has_value());
601+ suite.expectEqual(childExpected.value().getValue().value(), "child2");
602+ });
577603 }};
578604}
You can’t perform that action at this time.
0 commit comments