Skip to content

Commit

Permalink
Updated OutputIterator to require post increment to return a type con…
Browse files Browse the repository at this point in the history
…vertible to the iterator type.
  • Loading branch information
tahonermann committed Dec 9, 2016
1 parent 862126a commit 148eedb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion include/stl2/detail/iterator/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,11 @@ STL2_OPEN_NAMESPACE {
//
template <class I, class T>
concept bool OutputIterator() {
return Iterator<I>() && Writable<I, T>();
return Iterator<I>() &&
Writable<I, T>() &&
requires(I& i) {
{ i++ } -> const I&;
};
}

namespace models {
Expand Down
32 changes: 31 additions & 1 deletion test/iterator/basic_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,45 @@ std::ostream& operator<<(std::ostream& os, R&& rng) {

template <stl2::Iterator I>
class output_cursor {
class post_increment_proxy {
public:
post_increment_proxy(output_cursor& self) noexcept
: self_(self) {}

post_increment_proxy& operator*() noexcept {
return *this;
}

template <class T>
requires stl2::OutputIterator<I, const T&>()
post_increment_proxy& operator=(const T &t)
{
self_.write(t);
return *this;
}

output_cursor& self_;
};

public:
struct mixin : protected stl2::detail::ebo_box<output_cursor> {
mixin() = default;
mixin(const post_increment_proxy &p)
: mixin(p.self_) {}
using mixin::ebo_box::ebo_box;
};

output_cursor() = default;
constexpr output_cursor(I i) noexcept
: i_{i} {}

void next() noexcept {
}

post_increment_proxy post_increment() noexcept {
return post_increment_proxy{*this};
}

template <class T>
requires stl2::OutputIterator<I, const T&>()
constexpr void write(const T& t) noexcept {
Expand Down Expand Up @@ -644,7 +673,8 @@ void test_output() {
I i{wi};
*i++ = 1;
*i++ = 2;
*i++ = 3;
I i2 = i++;
*i2 = 3;
CHECK(vec[0] == 1);
CHECK(vec[1] == 2);
CHECK(vec[2] == 3);
Expand Down

0 comments on commit 148eedb

Please sign in to comment.