Skip to content

Commit

Permalink
Merge branch 'feature/std23-chunk' into feature/std23-stride
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 7, 2024
2 parents 76165bd + 90c7985 commit 6c5ee70
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/tools/std20/views/drop_while.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "tools/std20/algorithm/find.hpp"
#include "tools/std20/detail/views/range_adaptors.hpp"
#include "tools/std20/detail/views/semiregular_box.hpp"
#include "tools/std23/detail/views/nonpropegating_box.hpp"
#include "tools/std23/detail/views/nonpropagating_box.hpp"
#include "tools/std20/views/all.hpp"
#include "tools/std20/views/interface.hpp"

Expand Down Expand Up @@ -53,7 +53,7 @@ struct drop_while_view : view_interface<drop_while_view<R, Pred>> {
private:
R base_;
detail::semiregular_box<Pred> pred_;
std23::ranges::detail::nonpropegating_box<iterator_t<R>> cached_;
std23::ranges::detail::nonpropagating_box<iterator_t<R>> cached_;
};

template <typename R, typename Pred>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace detail {
/**
* @brief A helper type containing a value that gets reset upon move or copy
*
* Similar to the semiregular_box, the nonpropegating_box is a helper type for
* Similar to the semiregular_box, the nonpropagating_box is a helper type for
* implementing views. It stores an optional containing a value that gets
* reset upon move or copy.
*/
template < typename T >
struct nonpropegating_box : std::optional<T> {
struct nonpropagating_box : std::optional<T> {

static_assert( std::is_object_v< T > );

Expand All @@ -28,17 +28,17 @@ struct nonpropegating_box : std::optional<T> {

public:

nonpropegating_box() = default;
nonpropagating_box() = default;

constexpr nonpropegating_box( const nonpropegating_box& ) : value_( std::nullopt ) {}
constexpr nonpropagating_box( const nonpropagating_box& ) : value_( std::nullopt ) {}

constexpr nonpropegating_box( nonpropegating_box&& other ) :
constexpr nonpropagating_box( nonpropagating_box&& other ) :
value_( std::nullopt ) {

other.value_.reset();
}

constexpr nonpropegating_box& operator=( const nonpropegating_box& other ) {
constexpr nonpropagating_box& operator=( const nonpropagating_box& other ) {

if ( this != std::addressof( other ) ) {

Expand All @@ -47,7 +47,7 @@ struct nonpropegating_box : std::optional<T> {
return *this;
}

constexpr nonpropegating_box& operator=( nonpropegating_box&& other ) {
constexpr nonpropagating_box& operator=( nonpropagating_box&& other ) {

this->value_.reset();
other.value_.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/std23/detail/views/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_cpp_test( std23.details.views.nonpropegating_box nonpropegating_box.test.cpp )
add_cpp_test( std23.details.views.nonpropagating_box nonpropagating_box.test.cpp )
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
#include <catch2/catch_test_macros.hpp>

// what we are testing
#include "tools/std23/detail/views/nonpropegating_box.hpp"
#include "tools/std23/detail/views/nonpropagating_box.hpp"

// other includes
#include <vector>

// convenience typedefs
using namespace njoy::tools;

SCENARIO( "nonpropegating_box" ) {
SCENARIO( "nonpropagating_box" ) {

std::vector< double > values = { 1., 2., 3., 4. };
using Iterator = std::vector< double >::iterator;

THEN( "the default constructor makes an empty box" ) {

// default constructor: no content
std23::ranges::detail::nonpropegating_box< Iterator > box;
std23::ranges::detail::nonpropagating_box< Iterator > box;
CHECK( false == box.has_value() );
} // THEN

THEN( "emplace sets the content in the box" ) {

std23::ranges::detail::nonpropegating_box< Iterator > box;
std23::ranges::detail::nonpropagating_box< Iterator > box;
CHECK( false == box.has_value() );

// emplace
Expand All @@ -36,29 +36,29 @@ SCENARIO( "nonpropegating_box" ) {

THEN( "copy constructor" ) {

std23::ranges::detail::nonpropegating_box< Iterator > box;
std23::ranges::detail::nonpropagating_box< Iterator > box;
box.emplace( values.begin() );

// copy construction: other has no content, box unchanged
std23::ranges::detail::nonpropegating_box< Iterator > other( box );
std23::ranges::detail::nonpropagating_box< Iterator > other( box );
CHECK( false == other.has_value() );
CHECK( true == box.has_value() );
} // THEN

THEN( "move constructor" ) {

std23::ranges::detail::nonpropegating_box< Iterator > box;
std23::ranges::detail::nonpropagating_box< Iterator > box;
box.emplace( values.begin() );

// move construction: other has no content, box reset
std23::ranges::detail::nonpropegating_box< Iterator > other( std::move( box ) );
std23::ranges::detail::nonpropagating_box< Iterator > other( std::move( box ) );
CHECK( false == other.has_value() );
CHECK( false == box.has_value() );
} // THEN

THEN( "copy assignment" ) {

std23::ranges::detail::nonpropegating_box< Iterator > box, other;
std23::ranges::detail::nonpropagating_box< Iterator > box, other;
box.emplace( values.begin() );
other.emplace( values.end() );
CHECK( true == box.has_value() );
Expand All @@ -72,7 +72,7 @@ SCENARIO( "nonpropegating_box" ) {

THEN( "move assignment" ) {

std23::ranges::detail::nonpropegating_box< Iterator > box, other;
std23::ranges::detail::nonpropagating_box< Iterator > box, other;
box.emplace( values.begin() );
other.emplace( values.end() );
CHECK( true == box.has_value() );
Expand All @@ -84,4 +84,3 @@ SCENARIO( "nonpropegating_box" ) {
CHECK( false == other.has_value() );
} // THEN
} // SCENARIO

4 changes: 2 additions & 2 deletions src/tools/std23/views/chunk_by.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "tools/std20/detail/views/range_adaptors.hpp"
#include "tools/std20/detail/views/semiregular_box.hpp"
#include "tools/std23/detail/views/nonpropegating_box.hpp"
#include "tools/std23/detail/views/nonpropagating_box.hpp"
#include "tools/std20/algorithm/adjacent_find.hpp"
#include "tools/std20/functional.hpp"
#include "tools/std20/views/interface.hpp"
Expand Down Expand Up @@ -36,7 +36,7 @@ struct chunk_by_view : std20::ranges::view_interface< chunk_by_view< R, Pred > >

R base_;
std20::ranges::detail::semiregular_box< Pred > pred_;
std23::ranges::detail::nonpropegating_box< std20::ranges::iterator_t< R > > begin_;
std23::ranges::detail::nonpropagating_box< std20::ranges::iterator_t< R > > begin_;

struct iterator {

Expand Down

0 comments on commit 6c5ee70

Please sign in to comment.