-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
922f1d0
commit 5812977
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
// Copyright 2021 Ole Erik Peistorpet | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
|
||
#include "counted.h" | ||
#include "../auxi/assignable.h" | ||
|
||
/** @file | ||
*/ | ||
|
||
namespace oel | ||
{ | ||
|
||
template< typename Generator > | ||
class _generateIterator | ||
{ | ||
typename _detail::AssignableWrap<Generator>::Type _g; | ||
|
||
public: | ||
using iterator_category = std::input_iterator_tag; | ||
using reference = decltype( std::declval<Generator &>()() ); | ||
using pointer = void; | ||
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 reference operator*() | ||
{ | ||
return static_cast<Generator &>(_g)(); | ||
} | ||
|
||
constexpr _generateIterator & operator++() OEL_ALWAYS_INLINE { return *this; } | ||
constexpr void operator++(int) & OEL_ALWAYS_INLINE {} | ||
}; | ||
|
||
|
||
namespace view | ||
{ | ||
//! Returns a view that generates `count` elements by calling the given generator function | ||
/** | ||
* 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); }; | ||
} | ||
|
||
} // oel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters