Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/range/v3/iterator/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ namespace ranges

template<typename I>
CPP_concept_bool weakly_incrementable =
semiregular<I> &&
default_constructible<I> &&
movable<I> &&
CPP_fragment(ranges::weakly_incrementable_, I);

template<typename I>
Expand Down
8 changes: 7 additions & 1 deletion include/range/v3/iterator/counted_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ namespace ranges
cnt_ = i.count();
}

constexpr I base() const
constexpr auto base() const& -> CPP_ret(I)( //
requires copy_constructible<I>)
{
return current_;
}

constexpr auto base() &&
{
return std::move(current_);
}

constexpr iter_difference_t<I> count() const
{
return cnt_;
Expand Down
9 changes: 7 additions & 2 deletions include/range/v3/iterator/move_iterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace ranges

constexpr move_iterator() = default;
explicit move_iterator(I i)
: current_(i)
: current_(std::move(i))
{}
template<typename O>
CPP_ctor(move_iterator)(move_iterator<O> const & i)( //
Expand All @@ -58,10 +58,15 @@ namespace ranges
current_ = i.base();
return *this;
}
I base() const
auto base() const& -> CPP_ret(I)( //
requires copy_constructible<I>)
{
return current_;
}
I base() &&
{
return std::move(current_);
}
// clang-format off
auto CPP_auto_fun(operator*)()(const)
(
Expand Down
18 changes: 18 additions & 0 deletions test/iterator/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <range/v3/algorithm/copy.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
#include "range/v3/iterator/concepts.hpp"

using namespace ranges;

Expand Down Expand Up @@ -428,6 +429,23 @@ void deep_integration_test()

#endif

struct move_only_iterator {
using difference_type = std::ptrdiff_t;

move_only_iterator() = default;

move_only_iterator(move_only_iterator&&) = default;
move_only_iterator& operator=(move_only_iterator&&) = default;

move_only_iterator(move_only_iterator const&) = delete;
move_only_iterator& operator=(move_only_iterator const&) = delete;

move_only_iterator& operator++() { return *this; }
void operator++(int) { ++*this; }
};
static_assert(ranges::weakly_incrementable<move_only_iterator>, "");
static_assert(!ranges::incrementable<move_only_iterator>, "");

int main()
{
test_insert_iterator();
Expand Down