Skip to content

Commit 6e9c131

Browse files
authored
add mutable_type typedef to collection and user collection (#718)
* add `mutable_type` typedef for collections and user collection * simplify obtaining mutable type from collection
1 parent d3f0381 commit 6e9c131

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/podio/UserDataCollection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class UserDataCollection : public CollectionBase {
7272

7373
public:
7474
using value_type = typename std::vector<BasicType>::value_type;
75+
using mutable_type = value_type;
7576
using const_iterator = typename std::vector<BasicType>::const_iterator;
7677
using iterator = typename std::vector<BasicType>::iterator;
7778
using difference_type = typename std::vector<BasicType>::difference_type;

python/templates/Collection.h.jinja2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ A Collection is identified by an ID.
4545
class {{ class.bare_type }}Collection : public podio::CollectionBase {
4646
public:
4747
using value_type = {{ class.bare_type }};
48+
using mutable_type = Mutable{{ class.bare_type }};
4849
using const_iterator = {{ class.bare_type }}CollectionIterator;
4950
using iterator = {{ class.bare_type }}MutableCollectionIterator;
5051
using difference_type = ptrdiff_t;

tests/unittests/std_interoperability.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,23 +749,23 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
749749
// *r = o
750750
// iterator
751751
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_v<iterator, CollectionType::value_type>);
752-
STATIC_REQUIRE(traits::has_dereference_assignment_v<iterator, CollectionType::value_type::mutable_type>);
752+
STATIC_REQUIRE(traits::has_dereference_assignment_v<iterator, CollectionType::mutable_type>);
753753
{
754754
auto coll = CollectionType{};
755755
auto item = coll.create(13ull, 0., 0., 0., 0.);
756756
REQUIRE(coll.begin()->cellID() == 13ull);
757-
auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.};
757+
auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.};
758758
*coll.begin() = new_item;
759759
DOCUMENTED_FAILURE(coll.begin()->cellID() == 42ull);
760760
}
761761
// const_iterator
762762
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::value_type>);
763-
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::value_type::mutable_type>);
763+
STATIC_REQUIRE(traits::has_dereference_assignment_v<const_iterator, CollectionType::mutable_type>);
764764
{
765765
auto coll = CollectionType{};
766766
auto item = coll.create(13ull, 0., 0., 0., 0.);
767767
REQUIRE(coll.cbegin()->cellID() == 13ull);
768-
auto new_item = CollectionType::value_type::mutable_type{42ull, 0., 0., 0., 0.};
768+
auto new_item = CollectionType::mutable_type{42ull, 0., 0., 0., 0.};
769769
*coll.cbegin() = new_item;
770770
DOCUMENTED_FAILURE(coll.cbegin()->cellID() == 42ull);
771771
new_item.cellID(44ull);
@@ -792,14 +792,13 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
792792
// *r++ = o
793793
// iterator
794794
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type>);
795-
DOCUMENTED_STATIC_FAILURE(
796-
traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type::mutable_type>);
795+
DOCUMENTED_STATIC_FAILURE(traits::has_dereference_assignment_increment_v<iterator, CollectionType::mutable_type>);
797796
// TODO add runtime check for assignment validity like in '*r = o' case
798797
// const_iterator
799798
DOCUMENTED_STATIC_FAILURE(
800799
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::value_type>);
801800
DOCUMENTED_STATIC_FAILURE(
802-
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::value_type::mutable_type>);
801+
traits::has_dereference_assignment_increment_v<const_iterator, CollectionType::mutable_type>);
803802
// TODO add runtime check for assignment validity like in '*r = o' case
804803

805804
// iterator_category - not strictly necessary but advised
@@ -852,7 +851,7 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
852851
// insert immutable to not-SubsetCollection
853852
REQUIRE_THROWS_AS(it = CollectionType::value_type{}, std::invalid_argument);
854853
// insert mutable (implicit cast to immutable) to not-SubsetCollection
855-
REQUIRE_THROWS_AS(it = CollectionType::value_type::mutable_type{}, std::invalid_argument);
854+
REQUIRE_THROWS_AS(it = CollectionType::mutable_type{}, std::invalid_argument);
856855
auto subColl = CollectionType{};
857856
subColl.setSubsetCollection(true);
858857
auto subIt = std::back_inserter(subColl);

0 commit comments

Comments
 (0)