From 1d0de7b26a12a29af486b1fe97f72bcd2d26528a Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Thu, 6 Jun 2024 22:07:18 +0200 Subject: [PATCH] add value-initialization --- doc/collections_as_container.md | 6 +++--- python/templates/macros/iterator.jinja2 | 1 + tests/unittests/std_interoperability.cpp | 20 ++++++++------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/doc/collections_as_container.md b/doc/collections_as_container.md index 048f9a653..461c89403 100644 --- a/doc/collections_as_container.md +++ b/doc/collections_as_container.md @@ -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 | @@ -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 | |------------|-------------|-----------|-------------------------------------------|---------| diff --git a/python/templates/macros/iterator.jinja2 b/python/templates/macros/iterator.jinja2 index f66d54c2d..0bfe853fe 100644 --- a/python/templates/macros/iterator.jinja2 +++ b/python/templates/macros/iterator.jinja2 @@ -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; diff --git a/tests/unittests/std_interoperability.cpp b/tests/unittests/std_interoperability.cpp index 88090d5dc..a7c8c0a92 100644 --- a/tests/unittests/std_interoperability.cpp +++ b/tests/unittests/std_interoperability.cpp @@ -415,7 +415,7 @@ TEST_CASE("Collection and iterator concepts") { DOCUMENTED_STATIC_FAILURE(std::indirectly_readable); DOCUMENTED_STATIC_FAILURE(std::indirectly_writable); STATIC_REQUIRE(std::weakly_incrementable); - DOCUMENTED_STATIC_FAILURE(std::incrementable); + STATIC_REQUIRE(std::incrementable); STATIC_REQUIRE(std::input_or_output_iterator); DOCUMENTED_STATIC_FAILURE(std::input_iterator); DOCUMENTED_STATIC_FAILURE(std::output_iterator); @@ -428,7 +428,7 @@ TEST_CASE("Collection and iterator concepts") { DOCUMENTED_STATIC_FAILURE(std::indirectly_readable); DOCUMENTED_STATIC_FAILURE(std::indirectly_writable); STATIC_REQUIRE(std::weakly_incrementable); - DOCUMENTED_STATIC_FAILURE(std::incrementable); + STATIC_REQUIRE(std::incrementable); STATIC_REQUIRE(std::input_or_output_iterator); DOCUMENTED_STATIC_FAILURE(std::input_iterator); DOCUMENTED_STATIC_FAILURE(std::output_iterator); @@ -655,9 +655,9 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") { // DefaultConstructible // iterator - DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v); + STATIC_REQUIRE(std::is_default_constructible_v); // const_iterator - DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v); + STATIC_REQUIRE(std::is_default_constructible_v); // Multipass guarantee // iterator @@ -704,16 +704,12 @@ TEST_CASE("Collection iterators", "[collection][container][iterator][std]") { // Singular iterators // iterator STATIC_REQUIRE(traits::has_equality_comparator_v); - DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v); - //{ - // REQUIRE(iterator{} == iterator{}); - //} + STATIC_REQUIRE(std::is_default_constructible_v); + { REQUIRE(iterator{} == iterator{}); } // const_iterator STATIC_REQUIRE(traits::has_equality_comparator_v); - DOCUMENTED_STATIC_FAILURE(std::is_default_constructible_v); - //{ - // REQUIRE(const_iterator{} == const_iterator{}); - //} + STATIC_REQUIRE(std::is_default_constructible_v); + { REQUIRE(const_iterator{} == const_iterator{}); } // i++ // iterator