diff --git a/Framework/StackInterface/SecondaryView.h b/Framework/StackInterface/SecondaryView.h index 5ed96731a074becedc0272b6164c433ed996fb80..57798e84b5ddc348737098a9651938caf8947146 100644 --- a/Framework/StackInterface/SecondaryView.h +++ b/Framework/StackInterface/SecondaryView.h @@ -281,6 +281,12 @@ namespace corsika::stack { } return ConstStackIterator(*this, getSize() - 1 - i + 1); } + StackIterator at(unsigned int i) { + return StackIterator(*this, i); + } + ConstStackIterator at(unsigned int i) const { + return ConstStackIterator(*this, i); + } /// @} /** diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h index 103d7b63cf1132525d06175c5447745f87c3e614..5f22d8069cda679af8676f22c87f96bbc16b232e 100644 --- a/Framework/StackInterface/Stack.h +++ b/Framework/StackInterface/Stack.h @@ -210,6 +210,13 @@ namespace corsika::stack { } return ConstStackIterator(*this, getSize() - 1 - i); } + StackIterator at(unsigned int i) { + return StackIterator(*this, i); + } + + ConstStackIterator at(unsigned int i) const { + return ConstStackIterator(*this, i); + } /// @} StackIterator GetNextParticle() { diff --git a/Framework/StackInterface/testStackInterface.cc b/Framework/StackInterface/testStackInterface.cc index 25ba3e1af0bdfb582b4e814f93782422ec8cd49c..cef564e8b5f13dbdbd75a0c7229bc6dd551c20fa 100644 --- a/Framework/StackInterface/testStackInterface.cc +++ b/Framework/StackInterface/testStackInterface.cc @@ -40,10 +40,16 @@ TEST_CASE("Stack", "[Stack]") { // construct a valid Stack object StackTest s; s.Clear(); - s.AddParticle(std::tuple{0.}); + auto pTest0 = s.AddParticle(std::tuple{0.}); + CHECK(s.getSize() == 1); + auto pTest1 = s.AddParticle(std::tuple{1.}); s.Copy(s.cbegin(), s.begin()); s.Swap(s.begin(), s.begin()); CHECK(s.getSize() == 1); + auto pTestAt = s.at(0); + CHECK(pTestAt == pTest); + auto pTestFirst = s.first(); + CHECK(pTestFirst == pTest); } SECTION("construct") {