| 36 | |
| 37 | template <typename TContainerObjOrRef> |
| 38 | void TestViewCompileability(TContainerObjOrRef&& container) { |
| 39 | using TContainer = std::decay_t<TContainerObjOrRef>; |
| 40 | using TIterator = typename TContainer::iterator; |
| 41 | |
| 42 | static_assert(std::is_same_v<decltype(container.begin()), TIterator>); |
| 43 | |
| 44 | // iterator_traits must work! |
| 45 | using difference_type = typename std::iterator_traits<TIterator>::difference_type; |
| 46 | using value_type = typename std::iterator_traits<TIterator>::value_type; |
| 47 | using reference = typename std::iterator_traits<TIterator>::reference; |
| 48 | using pointer = typename std::iterator_traits<TIterator>::pointer; |
| 49 | |
| 50 | { |
| 51 | // operator assignment |
| 52 | auto it = container.begin(); |
| 53 | it = container.end(); |
| 54 | it = std::move(container.begin()); |
| 55 | // operator copying |
| 56 | auto it2 = it; |
| 57 | Y_UNUSED(it2); |
| 58 | auto it3 = std::move(it); |
| 59 | Y_UNUSED(it3); |
| 60 | Y_UNUSED(*it3); |
| 61 | EXPECT_TRUE(it3 == it3); |
| 62 | EXPECT_FALSE(it3 != it3); |
| 63 | // const TIterator |
| 64 | const auto it4 = it3; |
| 65 | Y_UNUSED(*it4); |
| 66 | EXPECT_TRUE(it4 == it4); |
| 67 | EXPECT_FALSE(it4 != it4); |
| 68 | EXPECT_TRUE(it3 == it4); |
| 69 | EXPECT_TRUE(it4 == it3); |
| 70 | EXPECT_FALSE(it3 != it4); |
| 71 | EXPECT_FALSE(it4 != it3); |
| 72 | } |
| 73 | |
| 74 | auto it = container.begin(); |
| 75 | |
| 76 | // sanity check for types |
| 77 | using TConstReference = const std::remove_reference_t<reference>&; |
| 78 | TConstReference ref = *it; |
| 79 | Y_UNUSED(ref); |
| 80 | (void) static_cast<value_type>(*it); |
| 81 | (void) static_cast<difference_type>(1); |
| 82 | if constexpr (std::is_reference_v<decltype(*it)>) { |
| 83 | pointer ptr = &*it; |
| 84 | Y_UNUSED(ptr); |
| 85 | } |
| 86 | |
| 87 | // std compatibility |
| 88 | ToVector(container); |
| 89 | |
| 90 | // const iterators |
| 91 | [](const auto& cont) { |
| 92 | auto constBeginIterator = cont.begin(); |
| 93 | auto constEndIterator = cont.end(); |
| 94 | static_assert(std::is_same_v<decltype(constBeginIterator), typename TContainer::const_iterator>); |
| 95 | Y_UNUSED(constBeginIterator); |