Skip to content

Commit

Permalink
add clarification *mutable* in std iterators vs *mutable* in podio
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed May 25, 2024
1 parent 72109a1 commit e25de51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion doc/collections_as_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ The C++ specifies a set of named requirements for iterators. Starting with C++20

### LegacyForwardIterator

In addition to the *LegacyForwardIterator* the C++ standard specifies also the *mutable LegacyForwardIterator*, which is both *LegacyForwardIterator* and *LegacyOutputIterator*. The term **mutable** used in this context doesn't imply mutability in the sense used in the PODIO.


| Requirement | Fulfilled by `iterator`/`const_iterator`? | Comment |
|-------------|-------------------------------------------|---------|
| [*LegacyInputIterator*](https://en.cppreference.com/w/cpp/named_req/InputIterator) | ❌ no / ❌ no | [See above](#legacyinputiterator)|
| [*DefaultConstructible*](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible) | ❌ no / ❌ no | Value initialization not defined |
| If mutable iterator then `reference` same as `value_type&` or `value_type&&`, otherwise same as `const value_type&` or `const value_type&&` | ❌ no / ❌ no | `reference` and `value_type` not defined |
| If *mutable* iterator then `reference` same as `value_type&` or `value_type&&`, otherwise same as `const value_type&` or `const value_type&&` | ❌ no / ❌ no | `reference` and `value_type` not defined |
| [Multipass guarantee](https://en.cppreference.com/w/cpp/named_req/ForwardIterator) | ❌ no / ❌ no | Copy constructor not defined |
| [Singular iterators](https://en.cppreference.com/w/cpp/named_req/ForwardIterator) | ❌ no / ❌ no | Value initialization not defined |

Expand Down
23 changes: 21 additions & 2 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,33 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {

} // end of LegacyInputIterator

// Mutable iterator: reference same as value_type& or value_type&&
// Mutable LegacyForwardIterator (LegacyForwardIterator that is also LegacyOutputIterator):
// - reference same as value_type& or value_type&&
// iterator
DOCUMENTED_STATIC_FAILURE(traits::has_reference_v<iterator>);
DOCUMENTED_STATIC_FAILURE(traits::has_value_type_v<iterator>);
// STATIC_REQUIRE(
// std::is_same_v<std::iterator_traits<iterator>::reference, std::iterator_traits<iterator>::value_type&> ||
// std::is_same_v<std::iterator_traits<iterator>::reference, std::iterator_traits<iterator>::value_type&&>);
// const_iterator
DOCUMENTED_STATIC_FAILURE(traits::has_reference_v<const_iterator>);
DOCUMENTED_STATIC_FAILURE(traits::has_value_type_v<const_iterator>);
// STATIC_REQUIRE(
// std::is_same_v<std::iterator_traits<const_iterator>::reference,
// std::iterator_traits<const_iterator>::value_type&> ||
// std::is_same_v<std::iterator_traits<const_iterator>::reference,
// std::iterator_traits<const_iterator>::value_type&&>);

// Immutable iterator: reference same as const value_type& or const value_type&&
// (Immutable) iterator:
// - reference same as const value_type& or const value_type&&
// iterator
DOCUMENTED_STATIC_FAILURE(traits::has_reference_v<iterator>);
DOCUMENTED_STATIC_FAILURE(traits::has_value_type_v<iterator>);
// STATIC_REQUIRE(std::is_same_v<std::iterator_traits<iterator>::reference,
// const std::iterator_traits<iterator>::value_type&> ||
// std::is_same_v<std::iterator_traits<iterator>::reference,
// const std::iterator_traits<iterator>::value_type&&>);
// const_iterator
DOCUMENTED_STATIC_FAILURE(traits::has_reference_v<const_iterator>);
DOCUMENTED_STATIC_FAILURE(traits::has_value_type_v<const_iterator>);
// STATIC_REQUIRE(std::is_same_v<std::iterator_traits<const_iterator>::reference,
Expand Down

0 comments on commit e25de51

Please sign in to comment.