Skip to content

Commit

Permalink
add tests for dereference assignment (and increment)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila committed May 9, 2024
1 parent 8a44937 commit 00503fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions doc/collections_as_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ The PODIO `Collection`s are move-only classes with emphasis on the distinction b

| Expression | Return type | Semantics | Fulfilled by `iterator`/`const_iterator`? | Comment |
|------------|-------------|-----------|-------------------------------------------|---------|
| `*r = o` | | | ❌ no / ❌ no | |
| `*r = o` | | | ✔️ yes / ❌ no | `iterator` defines assigning `value_type::mutable_type`, `const_iterator` doesn't define assignment |
| `++r` | `It&` | | ✔️ yes / ✔️ yes | |
| `r++` | Convertible to `const It&` | Same as `It temp = r; ++r; return temp;` | ❌ no / ❌ no | Post-increment not defined |
| `*r++ = o` | | Same as `*r = o; ++r;`| ✔️ yes / ❌ no | |
| `*r++ = o` | | Same as `*r = o; ++r;`| ❌ no / ❌ no | Post-increment not defined |

## Collection as AllocatorAwareContainer

Expand Down
32 changes: 25 additions & 7 deletions tests/unittests/std_interoperability.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/MutableExampleHit.h"
#include <catch2/catch_test_macros.hpp>
#include <iterator>
#include <limits>
Expand Down Expand Up @@ -204,6 +205,25 @@ template <class T>
struct has_postincrement<T, std::void_t<decltype(std::declval<T>()++)>> : std::true_type {};
template <typename T>
inline constexpr bool has_postincrement_v = has_postincrement<T>::value;

// *It = val
template <class, class, class = void>
struct has_dereference_assignment : std::false_type {};
template <class T, class Value>
struct has_dereference_assignment<T, Value, std::void_t<decltype(*std::declval<T>() = std::declval<Value>())>>
: std::true_type {};
template <typename T, typename Value>
inline constexpr bool has_dereference_assignment_v = has_dereference_assignment<T, Value>::value;

// *It++ = val
template <class, class, class = void>
struct has_dereference_assignment_increment : std::false_type {};
template <class T, class Value>
struct has_dereference_assignment_increment<T, Value,
std::void_t<decltype(*std::declval<T>()++ = std::declval<Value>())>>
: std::true_type {};
template <typename T, typename Value>
inline constexpr bool has_dereference_assignment_increment_v = has_dereference_assignment_increment<T, Value>::value;
} // namespace traits

TEST_CASE("Collection container types", "[collection][container][types][std]") {
Expand Down Expand Up @@ -485,7 +505,8 @@ TEST_CASE("Collection iterators", "[collection][container][interator][std]") {
STATIC_REQUIRE(std::is_pointer_v<const_iterator> || std::is_class_v<const_iterator>);

// *r = o
FAIL("Not implemented yet");
REQUIREMENT_NOT_MET(traits::has_dereference_assignment_v<iterator, CollectionType::value_type>);
STATIC_REQUIRE(traits::has_dereference_assignment_v<iterator, CollectionType::value_type::mutable_type>);

// ++r
STATIC_REQUIRE(traits::has_preincrement_v<iterator>);
Expand All @@ -497,7 +518,9 @@ TEST_CASE("Collection iterators", "[collection][container][interator][std]") {
// std::add_const_t<std::add_lvalue_reference_t<iterator>>>);

//*r++ =o
FAIL("Not implemented yet");
REQUIREMENT_NOT_MET(traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type>);
REQUIREMENT_NOT_MET(
traits::has_dereference_assignment_increment_v<iterator, CollectionType::value_type::mutable_type>);
}
}

Expand Down Expand Up @@ -539,9 +562,4 @@ TEST_CASE("Collection and std iterator adaptors", "[collection][container][adapt
FAIL("Not yet implemented");
}

TEST_CASE("Collection and std::algorithms", "[collection][container][algorithm][std]") {
auto a = CollectionType();
FAIL("Not yet implemented");
}

#undef REQUIREMENT_NOT_MET

0 comments on commit 00503fb

Please sign in to comment.