Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add == and != operators between S,I and I,S. Correct Tests and split
template for end() between iterator and sentinel
  • Loading branch information
joewpeterson committed Jun 18, 2024
commit ac1b4271df3695f532491762f7c9625117a50203
11 changes: 5 additions & 6 deletions src/tools/std23/views/test/zip.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ SCENARIO( "zip_view" ) {

THEN( "a stride_view can be constructed and members can be tested" ) {

// CHECK( false == chunk.empty() );
// CHECK( true == bool( chunk ) );
CHECK( false == chunk.empty() );
CHECK( true == bool( chunk ) );

CHECK( std20::ranges::equal( equal, chunk ) );

Expand Down Expand Up @@ -94,20 +94,19 @@ SCENARIO( "zip_view" ) {
CHECK( std20::ranges::bidirectional_range< Range > );
CHECK( ! std20::ranges::random_access_range< Range > );
CHECK( ! std20::ranges::contiguous_range< Range > );
CHECK( std20::ranges::common_range< Range > );
CHECK( ! std20::ranges::common_range< Range > );
}

THEN( "a stride_view can be constructed and members can be tested" ) {

CHECK( 7 == chunk.size() );

// CHECK( false == chunk.empty() );
// CHECK( true == bool( chunk ) );
CHECK( false == chunk.empty() );
CHECK( true == bool( chunk ) );

CHECK( std20::ranges::equal( equal, chunk ) );

CHECK( equal[0] == chunk.front() );
// CHECK( equal[6] == chunk.back() );
} // THEN
} // WHEN
} // GIVEN
Expand Down
60 changes: 44 additions & 16 deletions src/tools/std23/views/zip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,35 @@ struct zip_view : std20::ranges::view_interface< zip_view< Rs... > > {
-> std::enable_if_t< ( std20::ranges::sentinel_for<
std20::ranges::sentinel_t< maybe_const< Const, Rs > >,
std20::ranges::iterator_t< maybe_const< Other, Rs > > > && ... ), bool > {

return tuple_any_equals( left.current_, right.end_ );
}

template < bool Other >
friend constexpr auto operator==( const sentinel& left, const iterator< Other >& right )
-> std::enable_if_t< ( std20::ranges::sentinel_for<
std20::ranges::sentinel_t< maybe_const< Const, Rs > >,
std20::ranges::iterator_t< maybe_const< Other, Rs > > > && ... ), bool > {
return right == left;
}

template < bool Other >
friend constexpr auto operator!=( const iterator< Other >& left, const sentinel& right )
-> std::enable_if_t< ( std20::ranges::sentinel_for<
std20::ranges::sentinel_t< maybe_const< Const, Rs > >,
std20::ranges::iterator_t< maybe_const< Other, Rs > > > && ... ), bool > {

return !tuple_any_equals( left.current_, right.end_ );
}

template < bool Other >
friend constexpr auto operator!=( const sentinel& left, const iterator< Other >& right )
-> std::enable_if_t< ( std20::ranges::sentinel_for<
std20::ranges::sentinel_t< maybe_const< Const, Rs > >,
std20::ranges::iterator_t< maybe_const< Other, Rs > > > && ... ), bool > {

return right != left;
}

template < bool Other >
friend constexpr auto operator-( const iterator< Other >& left, const sentinel& right )
-> std::enable_if_t< ( std20::ranges::sized_sentinel_for<
Expand Down Expand Up @@ -429,13 +454,8 @@ struct zip_view : std20::ranges::view_interface< zip_view< Rs... > > {

template < bool Const = false >
constexpr auto end()
-> std::enable_if_t< ! zip_all_simple< Const, Rs... >, iterator< false > > {

if constexpr ( ! zip_is_common< Rs... > ) {

return sentinel< false >( tuple_transform( std20::ranges::end, this->views_ ));
}
else if constexpr ( ( std20::ranges::random_access_range< Rs > && ... ) ) {
-> std::enable_if_t< ! zip_all_simple< Const, Rs... > && zip_is_common< Rs... >, iterator< false > > {
if constexpr ( ( std20::ranges::random_access_range< Rs > && ... ) ) {

return this->begin() + std20::ranges::iter_difference_t< iterator< false > >( this->size() );
} else {
Expand All @@ -444,23 +464,31 @@ struct zip_view : std20::ranges::view_interface< zip_view< Rs... > > {
}
}

template < bool Const = true >
constexpr auto end() const
-> std::enable_if_t< zip_all_range< Const, Rs... >, iterator< true > > {
template < bool Const = false >
constexpr auto end()
-> std::enable_if_t< ! zip_all_simple< Const, Rs... > && ! zip_is_common< Rs... >, sentinel< false > > {
return sentinel< false >( tuple_transform( std20::ranges::end, this->views_ ));
}

if constexpr ( ! zip_is_common< Rs... > ) {

return sentinel< true >( tuple_transform( std20::ranges::end, this->views_ ));
}
else if constexpr ( ( std20::ranges::random_access_range< Rs > && ... ) ) {

template < bool Const = true >
constexpr auto end() const
-> std::enable_if_t< zip_all_range< Const, Rs... > && zip_is_common< Rs... >, iterator< true > > {
if constexpr ( ( std20::ranges::random_access_range< Rs > && ... ) ) {
return this->begin() + std20::ranges::iter_difference_t< iterator< true > >( this->size() );
} else {

return iterator< true >( tuple_transform( std20::ranges::end, this->views_ ) );
}
}

template < bool Const = true >
constexpr auto end() const
-> std::enable_if_t< zip_all_range< Const, Rs... > && ! zip_is_common< Rs... >, sentinel< true > > {
return sentinel< true >( tuple_transform( std20::ranges::end, this->views_ ));
}


template < bool Const = false >
constexpr auto size()
-> std::enable_if_t< zip_all_sized< Const, Rs... >, std::size_t > {
Expand Down