You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The std adaptors often rely on a typedef value_type. The PODIO mutable semantics complicate matters, as Collection::value_type is simply defined as an immutable type.
Collection push_back has overloads for both mutable and immutable types. The overloads have different behaviors, for instance, for Collection::value_type overload the non-subset collections throws:
invalid_argument: Can only add immutable objects to subset collections
While itself it's correct behavior, some std adapters do implicit conversion to value_type and end up using the overload for immutable type, e.g copying elements withstd::back_insert_iterator:
// this throws because the immutable type is pushedstd::transform(std::begin(a), std::end(a), std::back_inserter(b),
[](const ExampleHit& i) -> MutableExampleHit {
return i.clone();
});
// this doesn't throw since the mutable type is pushedstd::for_each(std::begin(a), std::end(a), [&b](constauto& i) {
b.push_back(i.clone());
});
I'm not sure if there are any possible solutions that don't change the value_type or push_back semantics
The text was updated successfully, but these errors were encountered:
m-fila
changed the title
collection push_back and value_type incompatible with std some iterator adaptors
collection push_back and value_type incompatible with some std iterator adaptors
Jan 25, 2024
This seems to be one of the things where our collections fail to fully satisfy things that are part of the std::vector contract, while mostly pretending to do so. Not sure if this one is salvageable or not, but we might have to think about a clearer distinction between our collections and the c++ STL containers (regarding member typedefs, member functions, etc...)
The std adaptors often rely on a typedef
value_type
. The PODIO mutable semantics complicate matters, asCollection::value_type
is simply defined as an immutable type.Collection
push_back
has overloads for both mutable and immutable types. The overloads have different behaviors, for instance, forCollection::value_type
overload the non-subset collections throws:While itself it's correct behavior, some std adapters do implicit conversion to
value_type
and end up using the overload for immutable type, e.g copying elements withstd::back_insert_iterator
:I'm not sure if there are any possible solutions that don't change the
value_type
orpush_back
semanticsThe text was updated successfully, but these errors were encountered: