Skip to content

Commit

Permalink
A few more updates to be in line with the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 14, 2024
1 parent 9a2cb67 commit 402009a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/tools/std23/test/usecase.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ SCENARIO( "use case" ) {
CHECK( std20::sized_range< DropChunk > );

// using StrideDrop = decltype( test.stride_drop() );
// auto begin = std20::ranges::begin( test.stride_drop() );
// auto end = std20::ranges::end( test.stride_drop() );
// CHECK( std20::view< StrideDrop > );
// CHECK( std20::range< StrideDrop > );
// CHECK( std20::random_access_range< StrideDrop > );
// CHECK( std20::sized_range< StrideDrop > );

// using ChunkDrop = decltype( test.chunk_drop() );
// auto begin1 = std20::ranges::begin( test.chunk_drop() );
// auto end1 = std20::ranges::end( test.chunk_drop() );
// CHECK( std20::view< ChunkDrop > );
// CHECK( std20::range< ChunkDrop > );
// CHECK( std20::random_access_range< ChunkDrop > );
Expand Down
6 changes: 5 additions & 1 deletion src/tools/std23/views/stride.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ struct stride_view : std20::ranges::view_interface< stride_view< R > > {
return { this, std20::ranges::begin( this->base_ ) };
}

template < typename RR = R, std::enable_if_t< !std20::ranges::detail::simple_view< RR >, int> = 0>
constexpr iterator< false > end() {

if constexpr ( std20::ranges::common_range< R > && std20::ranges::sized_range< R > ) {
Expand All @@ -300,9 +301,12 @@ struct stride_view : std20::ranges::view_interface< stride_view< R > > {
}
}

template < typename RR = R, std::enable_if_t< std20::ranges::range< const RR >, int > = 0 >
constexpr iterator< true > end() const {

if constexpr ( std20::ranges::common_range< R > && std20::ranges::sized_range< R > ) {
if constexpr ( std20::ranges::common_range< R > &&
std20::ranges::sized_range< R > &&
std20::ranges::forward_range< R > ) {

auto missing = ( this->stride_ - std20::ranges::distance( this->base_ ) % this->stride_ ) % this->stride_;
return iterator< true >( this, std20::ranges::end( this->base_ ), missing );
Expand Down
6 changes: 3 additions & 3 deletions src/tools/std23/views/test/stride.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SCENARIO( "stride_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" ) {
Expand Down Expand Up @@ -74,7 +74,7 @@ SCENARIO( "stride_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" ) {
Expand Down Expand Up @@ -113,7 +113,7 @@ SCENARIO( "stride_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" ) {
Expand Down

0 comments on commit 402009a

Please sign in to comment.