Skip to content

Commit

Permalink
Merge pull request #8 from njoy/feature/ranges-part2
Browse files Browse the repository at this point in the history
Feature/ranges part2
  • Loading branch information
whaeck authored Nov 8, 2023
2 parents 28db74e + b07d0c0 commit 4873558
Show file tree
Hide file tree
Showing 15 changed files with 794 additions and 294 deletions.
3 changes: 2 additions & 1 deletion cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory( src/tools/concepts/IsRange/test )
add_subdirectory( src/tools/concepts/IsIterator/test )

add_subdirectory( src/tools/ranges/IteratorView/test )
add_subdirectory( src/tools/ranges/TransformIterator/test )
add_subdirectory( src/tools/ranges/TransformView/test )
add_subdirectory( src/tools/ranges/TransformView/Iterator/test )
add_subdirectory( src/tools/ranges/make_view/test )
add_subdirectory( src/tools/ranges/make_transform_view/test )
1 change: 1 addition & 0 deletions src/tools.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "tools/overload.hpp"
#include "tools/concepts.hpp"
#include "tools/ranges.hpp"

#include "tools/Log.hpp"
14 changes: 12 additions & 2 deletions src/tools/ranges/IteratorView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

// system includes
#include <iterator>
#include <stdexcept>

// other includes
#include "tools/ranges/ViewBase.hpp"
Expand All @@ -16,7 +15,7 @@ namespace ranges {
*
* @brief A simple iterator based view class
*
* Currently only defined for random access iterators.
* It works on all types of iterators (input, forward, bidirectional and random).
*/
template < typename Iterator >
class IteratorView : public ViewBase< IteratorView< Iterator > > {
Expand All @@ -30,6 +29,7 @@ class IteratorView : public ViewBase< IteratorView< Iterator > > {
using reference = typename std::iterator_traits< Iterator >::reference;
using const_reference = const reference;
using iterator = Iterator;
using const_iterator = const Iterator;

private:

Expand Down Expand Up @@ -66,6 +66,16 @@ class IteratorView : public ViewBase< IteratorView< Iterator > > {
* @brief Return the end iterator to the view
*/
constexpr iterator end() const noexcept { return end_; }

/**
* @brief Return the begin iterator to the view
*/
constexpr const_iterator cbegin() const noexcept { return this->begin(); }

/**
* @brief Return the end iterator to the view
*/
constexpr const_iterator cend() const noexcept { return this->end(); }
};

/**
Expand Down
21 changes: 21 additions & 0 deletions src/tools/ranges/IteratorView/test/IteratorView.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ SCENARIO( "IteratorView" ) {
CHECK( false == chunk.empty() );
CHECK( false == bool( chunk ) );

unsigned int counter = 0;
for ( auto value : chunk ) {

++counter;
}
CHECK( 5 == counter );

// the following should not compile: no random access iterator
// CHECK( -2 == chunk[0] );
// CHECK( -2 == chunk.at(0) );
Expand Down Expand Up @@ -60,6 +67,13 @@ SCENARIO( "IteratorView" ) {
CHECK( false == chunk.empty() );
CHECK( false == bool( chunk ) );

unsigned int counter = 0;
for ( auto value : chunk ) {

++counter;
}
CHECK( 5 == counter );

// the following should not compile: no random access iterator
// CHECK( -2 == chunk[0] );
// CHECK( -2 == chunk.at(0) );
Expand Down Expand Up @@ -87,6 +101,13 @@ SCENARIO( "IteratorView" ) {
CHECK( false == chunk.empty() );
CHECK( false == bool( chunk ) );

unsigned int counter = 0;
for ( auto value : chunk ) {

++counter;
}
CHECK( 5 == counter );

CHECK( -2 == chunk[0] );
CHECK( -1 == chunk[1] );
CHECK( 0 == chunk[2] );
Expand Down
157 changes: 0 additions & 157 deletions src/tools/ranges/TransformIterator.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/tools/ranges/TransformIterator/test/CMakeLists.txt

This file was deleted.

85 changes: 0 additions & 85 deletions src/tools/ranges/TransformIterator/test/TransformIterator.test.cpp

This file was deleted.

Loading

0 comments on commit 4873558

Please sign in to comment.