Skip to content
This repository has been archived by the owner on Jan 2, 2022. It is now read-only.

Commit

Permalink
Iterators...
Browse files Browse the repository at this point in the history
  • Loading branch information
jtomschroeder committed Aug 19, 2016
1 parent c1af0c4 commit 3e52dd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/lambda/core/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 10,15 @@ namespace detail {
struct nope {};
}

// iterator has begin(T) and end(T)
//
// iterator has T.begin() and T.end()
// TODO! T::value_type, T
//
template <typename T>
struct is_iterator {
private:
template <typename G>
static auto check(G &&g) -> std::pair<decltype(begin(g)), decltype(end(g))>;
static auto check(G &&g) -> std::pair<decltype(g.begin()), decltype(g.end())>;

static detail::nope check(...);

Expand Down
10 changes: 5 additions & 5 deletions lib/lambda/stream/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 18,20 @@ template <class R>
class Range : public Stream {
R range;

decltype(begin(range)) begin_;
decltype(end(range)) end_;
decltype(range.begin()) begin_;
decltype(range.end()) end_;

public:
using Type = typename R::value_type;

explicit Range(R &&range) : range(range), begin_(begin(range)), end_(end(range)) {}
explicit Range(R range) : range(range), begin_(range.begin()), end_(range.end()) {}

Maybe<Type> next() { return begin_ != end_ ? some(std::move(*begin_ )) : none; }
};

template <class R, REQUIRE_CONCEPT(is_iterator_v<R>)>
auto stream(R &&c) {
return Range<R>{std::forward<R>(c)};
auto stream(R range) {
return Range<R>{std::move(range)};
}

template <class F>
Expand Down

0 comments on commit 3e52dd9

Please sign in to comment.