Skip to content

Commit

Permalink
Making sure the views are const
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Nov 2, 2023
1 parent 2d0fab5 commit faa464d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/tools/ranges/IteratorView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,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
3 changes: 2 additions & 1 deletion src/tools/ranges/TransformView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ template < typename Range, typename Transform >
class TransformView : public ViewBase< TransformView< Range, Transform > > {

/* type aliases */
using BaseIterator = typename Range::const_iterator;
using BaseIterator = decltype( std::cbegin( std::declval< Range& >() ) );

/* fields */
Range base_;
Expand All @@ -41,6 +41,7 @@ class TransformView : public ViewBase< TransformView< Range, Transform > > {
using reference = typename std::iterator_traits< Iterator >::reference;
using const_reference = const reference;
using iterator = Iterator;
using const_iterator = const Iterator;

/* constructor */

Expand Down
4 changes: 3 additions & 1 deletion src/tools/ranges/make_transform_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// system includes

// other includes
#include "tools/ranges/IteratorView.hpp"
#include "tools/ranges/TransformView.hpp"

namespace njoy {
Expand All @@ -20,7 +21,8 @@ template < typename Container, typename Transformation >
constexpr auto make_transform_view( Container&& container,
Transformation transformation ) {

return TransformView( container, std::move( transformation ) );
return TransformView( IteratorView( container.cbegin(), container.cend() ),
std::move( transformation ) );
}

} // ranges namespace
Expand Down

0 comments on commit faa464d

Please sign in to comment.