diff --git a/include/podio/UserDataCollection.h b/include/podio/UserDataCollection.h index 226d412fe..35bc9c9bc 100644 --- a/include/podio/UserDataCollection.h +++ b/include/podio/UserDataCollection.h @@ -72,6 +72,7 @@ class UserDataCollection : public CollectionBase { public: using value_type = typename std::vector::value_type; + using mutable_type = value_type; using const_iterator = typename std::vector::const_iterator; using iterator = typename std::vector::iterator; using difference_type = typename std::vector::difference_type; diff --git a/python/templates/Collection.h.jinja2 b/python/templates/Collection.h.jinja2 index 3ebbe3866..53be2ddb3 100644 --- a/python/templates/Collection.h.jinja2 +++ b/python/templates/Collection.h.jinja2 @@ -45,6 +45,7 @@ A Collection is identified by an ID. class {{ class.bare_type }}Collection : public podio::CollectionBase { public: using value_type = {{ class.bare_type }}; + using mutable_type = Mutable{{ class.bare_type }}; using const_iterator = {{ class.bare_type }}CollectionIterator; using iterator = {{ class.bare_type }}MutableCollectionIterator; using difference_type = ptrdiff_t; diff --git a/tests/unittests/std_interoperability.cpp b/tests/unittests/std_interoperability.cpp index 389084f59..cde0fdb54 100644 --- a/tests/unittests/std_interoperability.cpp +++ b/tests/unittests/std_interoperability.cpp @@ -749,23 +749,23 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") { // *r = o // iterator DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_v); - STATIC_REQUIRE(traits::has_dereference_assignment_v); + STATIC_REQUIRE(traits::has_dereference_assignment_v); { auto coll = CollectionType{}; auto item = coll.create(13ull, 0., 0., 0., 0.); REQUIRE(coll.begin()->cellID() == 13ull); - auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.}; + auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.}; *coll.begin() = new_item; DOCUMENTED_FAILURE(coll.begin()->cellID() == 42ull); } // const_iterator STATIC_REQUIRE(traits::has_dereference_assignment_v); - STATIC_REQUIRE(traits::has_dereference_assignment_v); + STATIC_REQUIRE(traits::has_dereference_assignment_v); { auto coll = CollectionType{}; auto item = coll.create(13ull, 0., 0., 0., 0.); REQUIRE(coll.cbegin()->cellID() == 13ull); - auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.}; + auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.}; *coll.cbegin() = new_item; DOCUMENTED_FAILURE(coll.cbegin()->cellID() == 42ull); new_item.cellID(44ull); @@ -792,14 +792,13 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") { // *r++ = o // iterator DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v); - DOCUMENTED_STATIC_FAILURE( - traits::has_dereference_assignment_increment_v); + DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v); // TODO add runtime check for assignment validity like in '*r = o' case // const_iterator DOCUMENTED_STATIC_FAILURE( traits::has_dereference_assignment_increment_v); DOCUMENTED_STATIC_FAILURE( - traits::has_dereference_assignment_increment_v); + traits::has_dereference_assignment_increment_v); // TODO add runtime check for assignment validity like in '*r = o' case // iterator_category - not strictly necessary but advised @@ -852,7 +851,7 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt // insert immutable to not-SubsetCollection REQUIRE_THROWS_AS(it = CollectionType::value_type{}, std::invalid_argument); // insert mutable (implicit cast to immutable) to not-SubsetCollection - REQUIRE_THROWS_AS(it = CollectionType::value_type::mutable_type{}, std::invalid_argument); + REQUIRE_THROWS_AS(it = CollectionType::mutable_type{}, std::invalid_argument); auto subColl = CollectionType{}; subColl.setSubsetCollection(true); auto subIt = std::back_inserter(subColl);