diff --git a/src/tools/ranges/AnyIterator.hpp b/src/tools/ranges/AnyIterator.hpp index e1be04a..0e56228 100644 --- a/src/tools/ranges/AnyIterator.hpp +++ b/src/tools/ranges/AnyIterator.hpp @@ -44,22 +44,22 @@ class AnyIterator { template < typename Iterator > AnyIterator( const std::input_iterator_tag&, Iterator&& iter ) : - ptr_( new AnyInputIteratorModel< typename std::decay< Iterator >::type, + ptr_( new AnyInputIteratorModel< Iterator, ValueType >( std::forward< Iterator >( iter ) ) ) {} template < typename Iterator > AnyIterator( const std::forward_iterator_tag&, Iterator&& iter ) : - ptr_( new AnyForwardIteratorModel< typename std::decay< Iterator >::type, + ptr_( new AnyForwardIteratorModel< Iterator, ValueType >( std::forward< Iterator >( iter ) ) ) {} template < typename Iterator > AnyIterator( const std::bidirectional_iterator_tag&, Iterator&& iter ) : - ptr_( new AnyBidirectionalIteratorModel< typename std::decay< Iterator >::type, + ptr_( new AnyBidirectionalIteratorModel< Iterator, ValueType >( std::forward< Iterator >( iter ) ) ) {} template < typename Iterator > AnyIterator( const std::random_access_iterator_tag&, Iterator&& iter ) : - ptr_( new AnyRandomAccessIteratorModel< typename std::decay< Iterator >::type, + ptr_( new AnyRandomAccessIteratorModel< Iterator, ValueType >( std::forward< Iterator >( iter ) ) ) {} public: diff --git a/src/tools/ranges/AnyView/test/CMakeLists.txt b/src/tools/ranges/AnyView/test/CMakeLists.txt index 5ee6108..934df1d 100644 --- a/src/tools/ranges/AnyView/test/CMakeLists.txt +++ b/src/tools/ranges/AnyView/test/CMakeLists.txt @@ -1 +1,2 @@ add_cpp_test( ranges.AnyView AnyView.test.cpp ) +add_cpp_test( ranges.AnyView.usecase usecase.test.cpp ) diff --git a/src/tools/ranges/AnyView/test/usecase.test.cpp b/src/tools/ranges/AnyView/test/usecase.test.cpp new file mode 100644 index 0000000..21a7f32 --- /dev/null +++ b/src/tools/ranges/AnyView/test/usecase.test.cpp @@ -0,0 +1,70 @@ +// include Catch2 +#include + +// what we are testing +#include "tools/ranges/AnyView.hpp" + +// other includes +#include +#include +#include +#include "tools/ranges/make_view.hpp" + +// convenience typedefs +using namespace njoy::tools::ranges; + +// a class with data +class Data { + + std::vector< double > data_; + +public: + + Data( int size ) : data_( size ) { + + for ( unsigned int i = 0; i < data_.size(); ++i ) { + + data_[i] = i; + } + } + + const std::vector< double >& data() const { return this->data_; } + + auto view() const { return njoy::tools::ranges::make_view( this->data() ); } +}; + +SCENARIO( "use case" ) { + + GIVEN( "a data object that returns a range" ) { + + Data object( 1000 ); + + WHEN( "retrieving the view and converting it to an AnyView" ) { + + AnyRandomAccessView< double > chunk = object.view(); + + THEN( "an AnyView can be constructed and members can be tested" ) { + + CHECK( 1000 == chunk.size() ); + CHECK( false == chunk.empty() ); + CHECK( false == bool( chunk ) ); + + unsigned int counter = 0; + for ( auto value : chunk ) { + + ++counter; + } + CHECK( 1000 == counter ); + + CHECK( 0 == chunk[0] ); + CHECK( 999 == chunk[999] ); + + CHECK( 0 == chunk.at( 0 ) ); + CHECK( 999 == chunk.at( 999 ) ); + + CHECK( 0 == chunk.front() ); + CHECK( 999 == chunk.back() ); + } // THEN + } // WHEN + } // GIVEN +} // SCENARIO