File indexing completed on 2026-11-30 10:31:07
0001 #ifndef PODIO_UTILITIES_BACKINSERTITERATOR_H
0002 #define PODIO_UTILITIES_BACKINSERTITERATOR_H
0003
0004 #include <cstddef>
0005 #include <iterator>
0006 #include <memory>
0007 #include <utility>
0008
0009 namespace podio {
0010
0011
0012
0013
0014
0015
0016
0017 template <typename Collection>
0018 class BackInsertIterator {
0019 public:
0020 using container_type = Collection;
0021 using iterator_category = std::output_iterator_tag;
0022 using value_type = void;
0023 using difference_type = std::ptrdiff_t;
0024 using pointer = void;
0025 using reference = void;
0026
0027 BackInsertIterator() = default;
0028
0029 explicit BackInsertIterator(Collection& collection) noexcept : m_collection(std::addressof(collection)) {
0030 }
0031
0032 template <typename T>
0033 requires requires(Collection& collection, T&& value) { collection.push_back(std::forward<T>(value)); }
0034 BackInsertIterator& operator=(T&& value) {
0035 m_collection->push_back(std::forward<T>(value));
0036 return *this;
0037 }
0038
0039 BackInsertIterator& operator*() noexcept {
0040 return *this;
0041 }
0042
0043 BackInsertIterator& operator++() noexcept {
0044 return *this;
0045 }
0046
0047 BackInsertIterator operator++(int) noexcept {
0048 return *this;
0049 }
0050
0051 private:
0052 Collection* m_collection{nullptr};
0053 };
0054
0055
0056 template <typename Collection>
0057 BackInsertIterator<Collection> back_inserter(Collection& collection) noexcept {
0058 return BackInsertIterator<Collection>(collection);
0059 }
0060
0061 }
0062
0063 #endif