Skip to content

Commit

Permalink
add value-initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed Jun 10, 2024
1 parent 023562a commit 7117c3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions doc/collections_as_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ In the following tables a convention from `Collection` is used: `iterator` stand
| `std::indirectly_readable` | ❌ no | ❌ no |
| `std::indirectly_writable` | ❌ no | ❌ no |
| `std::weakly_incrementable` | ✔️ yes | ✔️ yes |
| `std::incrementable` | ❌ no | ❌ no |
| `std::incrementable` | ✔️ yes | ✔️ yes |
| `std::input_or_output_iterator` | ✔️ yes | ✔️ yes |
| `std::input_iterator` | ❌ no | ❌ no |
| `std::output_iterator` | ❌ no | ❌ no |
Expand Down Expand Up @@ -134,10 +134,10 @@ In addition to the *LegacyForwardIterator* the C++ standard specifies also the *
| Requirement | Fulfilled by `iterator`/`const_iterator`? | Comment |
|-------------|-------------------------------------------|---------|
| [*LegacyInputIterator*](https://en.cppreference.com/w/cpp/named_req/InputIterator) | ✔️ yes / ✔️ yes | [See above](#legacyinputiterator)|
| [*DefaultConstructible*](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible) | ❌ no / ❌ no | Value initialization not defined |
| [*DefaultConstructible*](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible) | ✔️ yes / ✔️ yes | |
| 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` type is not a reference (`&` or `&&`) |
| [Multipass guarantee](https://en.cppreference.com/w/cpp/named_req/ForwardIterator) | ❌ no / ❌ no | References from dereferencing equal iterators aren't bound to the same object |
| [Singular iterators](https://en.cppreference.com/w/cpp/named_req/ForwardIterator) | ❌ no / ❌ no | Value initialization not defined |
| [Singular iterators](https://en.cppreference.com/w/cpp/named_req/ForwardIterator) | ✔️ yes / ✔️ yes | |

| Expression | Return type | Semantics | Fulfilled by `iterator`/`const_iterator`? | Comment |
|------------|-------------|-----------|-------------------------------------------|---------|
Expand Down
1 change: 1 addition & 0 deletions python/templates/macros/iterator.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public:
using iterator_category = std::input_iterator_tag;

{{ iterator_type }}(size_t index, const {{ class.bare_type }}ObjPointerContainer* collection) : m_index(index), m_object({{ ptr_init }}), m_collection(collection) {}
{{ iterator_type }}(): {{ iterator_type }}(0, nullptr) {}

{{ iterator_type }}(const {{ iterator_type }}&) = default;
{{ iterator_type }}({{ iterator_type }}&&) = default;
Expand Down
20 changes: 8 additions & 12 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ TEST_CASE("Collection and iterator concepts") {
DOCUMENTED_STATIC_FAILURE(std::indirectly_readable<iterator>);
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<iterator, CollectionType::value_type>);
STATIC_REQUIRE(std::weakly_incrementable<iterator>);
DOCUMENTED_STATIC_FAILURE(std::incrementable<iterator>);
STATIC_REQUIRE(std::incrementable<iterator>);
STATIC_REQUIRE(std::input_or_output_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::input_iterator<iterator>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<iterator, CollectionType::value_type>);
Expand All @@ -428,7 +428,7 @@ TEST_CASE("Collection and iterator concepts") {
DOCUMENTED_STATIC_FAILURE(std::indirectly_readable<const_iterator>);
DOCUMENTED_STATIC_FAILURE(std::indirectly_writable<const_iterator, CollectionType::value_type>);
STATIC_REQUIRE(std::weakly_incrementable<const_iterator>);
DOCUMENTED_STATIC_FAILURE(std::incrementable<const_iterator>);
STATIC_REQUIRE(std::incrementable<const_iterator>);
STATIC_REQUIRE(std::input_or_output_iterator<const_iterator>);
DOCUMENTED_STATIC_FAILURE(std::input_iterator<const_iterator>);
DOCUMENTED_STATIC_FAILURE(std::output_iterator<const_iterator, CollectionType::value_type>);
Expand Down Expand Up @@ -655,9 +655,9 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {

// DefaultConstructible
// iterator
DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v<iterator>);
STATIC_REQUIRE(std::is_default_constructible_v<iterator>);
// const_iterator
DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v<const_iterator>);
STATIC_REQUIRE(std::is_default_constructible_v<const_iterator>);

// Multipass guarantee
// iterator
Expand Down Expand Up @@ -704,16 +704,12 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") {
// Singular iterators
// iterator
STATIC_REQUIRE(traits::has_equality_comparator_v<iterator>);
DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v<iterator>);
//{
// REQUIRE(iterator{} == iterator{});
//}
STATIC_REQUIRE(std::is_default_constructible_v<iterator>);
{ REQUIRE(iterator{} == iterator{}); }
// const_iterator
STATIC_REQUIRE(traits::has_equality_comparator_v<const_iterator>);
DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v<const_iterator>);
//{
// REQUIRE(const_iterator{} == const_iterator{});
//}
STATIC_REQUIRE(std::is_default_constructible_v<const_iterator>);
{ REQUIRE(const_iterator{} == const_iterator{}); }

// i++
// iterator
Expand Down

0 comments on commit 7117c3f

Please sign in to comment.