diff --git a/include/openPMD/snapshots/ContainerImpls.hpp b/include/openPMD/snapshots/ContainerImpls.hpp index adc14c1be7..510fe1b768 100644 --- a/include/openPMD/snapshots/ContainerImpls.hpp +++ b/include/openPMD/snapshots/ContainerImpls.hpp @@ -20,7 +20,7 @@ class StatefulSnapshotsContainer : public AbstractSnapshotsContainer auto get() const -> StatefulIterator const *; public: - using AbstractSnapshotsContainer::currentIteration; + auto currentIteration() -> std::optional override; auto currentIteration() const -> std::optional override; auto begin() -> iterator override; diff --git a/src/snapshots/ContainerImpls.cpp b/src/snapshots/ContainerImpls.cpp index 11524d5eec..5719d125d1 100644 --- a/src/snapshots/ContainerImpls.cpp +++ b/src/snapshots/ContainerImpls.cpp @@ -39,10 +39,29 @@ auto StatefulSnapshotsContainer::get() const -> StatefulIterator const * { return m_bufferedIterator.value_or(nullptr); } +auto StatefulSnapshotsContainer::currentIteration() + -> std::optional +{ + if (auto it = get(); it) + { + return it->peekCurrentlyOpenIteration(); + } + else + { + return nullptr; + } +} auto StatefulSnapshotsContainer::currentIteration() const -> std::optional { - return get()->peekCurrentlyOpenIteration(); + if (auto it = get(); it) + { + return it->peekCurrentlyOpenIteration(); + } + else + { + return nullptr; + } } auto StatefulSnapshotsContainer::begin() -> iterator { @@ -93,7 +112,8 @@ auto StatefulSnapshotsContainer::rend() const -> const_iterator bool StatefulSnapshotsContainer::empty() const { - return get()->operator bool(); + auto it = get(); + return (!it) || it->operator bool(); } auto StatefulSnapshotsContainer::at(key_type const &) const