Skip to content

Commit

Permalink
Hack: generate_iterator with mutable member
Browse files Browse the repository at this point in the history
for std::input_iterator concept
  • Loading branch information
OleErikPeistorpet committed Jun 14, 2024
1 parent b3162e5 commit 4463663
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion unit_test/view_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ TEST(viewTest, viewMoveMutableEmptyAndSize)
}

using IntGenIter = oel::iterator_t<decltype( view::generate(Ints{}, 0) )>;
static_assert(std::input_or_output_iterator<IntGenIter>);
static_assert(std::input_iterator<IntGenIter>);

TEST(viewTest, chainWithStd)
{
Expand Down
12 changes: 6 additions & 6 deletions view/generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace oel
{

template< typename Generator >
class _generateIterator
class generate_iterator
{
typename _detail::AssignableWrap<Generator>::Type _g;
typename _detail::AssignableWrap<Generator>::Type mutable _g;

public:
using iterator_category = std::input_iterator_tag;
Expand All @@ -27,14 +27,14 @@ class _generateIterator
using value_type = std::remove_cv_t< std::remove_reference_t<reference> >;
using difference_type = ptrdiff_t;

constexpr explicit _generateIterator(Generator g) : _g{std::move(g)} {}
constexpr explicit generate_iterator(Generator g) : _g{std::move(g)} {}

constexpr reference operator*()
constexpr reference operator*() const
{
return static_cast<Generator &>(_g)();
}

constexpr _generateIterator & operator++() OEL_ALWAYS_INLINE { return *this; }
constexpr generate_iterator & operator++() OEL_ALWAYS_INLINE { return *this; }
constexpr void operator++(int) & OEL_ALWAYS_INLINE {}
};

Expand All @@ -45,7 +45,7 @@ namespace view
/**
* Like `generate_n` in the Range-v3 library, but this is only for use within OE-Lib. */
inline constexpr auto generate =
[](auto generator, ptrdiff_t count) { return counted(_generateIterator{std::move(generator)}, count); };
[](auto generator, ptrdiff_t count) { return counted(generate_iterator{std::move(generator)}, count); };
}

} // oel

0 comments on commit 4463663

Please sign in to comment.