move mark object vmake::rng::require_unique -> vmake::require_unique
This commit is contained in:
parent
b846678d29
commit
0d0edbb549
@ -4,7 +4,7 @@ using namespace std;
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_ints(1, 10), 15));
|
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_ints(1, 10), 15));
|
||||||
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_ints(vmake::rng::require_unique, 1, 20), 15));
|
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_ints(vmake::require_unique, 1, 20), 15));
|
||||||
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_reals(1., 10.), 5));
|
vmake::outputln(cout, " ", vmake::take(vmake::rng::uniform_reals(1., 10.), 5));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
namespace vmake {
|
namespace vmake {
|
||||||
|
|
||||||
|
struct require_unique_t {} require_unique;
|
||||||
|
|
||||||
struct sequence_terminated_error : std::exception {
|
struct sequence_terminated_error : std::exception {
|
||||||
virtual const char *what() const noexcept override final {
|
virtual const char *what() const noexcept override final {
|
||||||
return "iterating on a terminated sequence.";
|
return "iterating on a terminated sequence.";
|
||||||
@ -27,11 +29,10 @@ inline constexpr auto as_const_reference(typename as_const_reference_t<T>::type
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
using optional = std::optional<T>;
|
using std::optional;
|
||||||
#else
|
#else
|
||||||
using optional = nonstd::optional<T>;
|
using nonstd::optional;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace polyfill
|
} // namespace polyfill
|
||||||
@ -138,16 +139,22 @@ struct ranged_iterator_extractor {
|
|||||||
using result = typename std::remove_reference<decltype(*std::declval<ContIt>())>::type;
|
using result = typename std::remove_reference<decltype(*std::declval<ContIt>())>::type;
|
||||||
|
|
||||||
ContIt cur, end;
|
ContIt cur, end;
|
||||||
|
bool added;
|
||||||
|
|
||||||
ranged_iterator_extractor(const ContIt &begin, const ContIt &end) : cur(begin), end(end) {}
|
ranged_iterator_extractor(const ContIt &begin, const ContIt &end) : cur(begin)
|
||||||
|
, end(end), added(false) {}
|
||||||
|
|
||||||
bool is_terminated() const noexcept {
|
bool is_terminated() const noexcept {
|
||||||
return cur == end;
|
return cur == end;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto operator()() {
|
auto operator()() {
|
||||||
|
// WARN: use for strange iterators such as std::istream_iterator
|
||||||
|
// do NOT try to optimize this into *it++
|
||||||
if (cur == end) throw sequence_terminated_error();
|
if (cur == end) throw sequence_terminated_error();
|
||||||
return *cur++;
|
if (added) return *++cur;
|
||||||
|
added = true;
|
||||||
|
return *cur;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,15 +205,13 @@ struct generator {
|
|||||||
|
|
||||||
Func g;
|
Func g;
|
||||||
|
|
||||||
generator(Func &&g) : g(g) {}
|
generator(Func &&g) : g(std::forward<Func>(g)) {}
|
||||||
generator(const Func &g) : g(g) {}
|
generator(const Func &g) : g(g) {}
|
||||||
|
|
||||||
generator<Func>& operator=(generator<Func> &&y) = default;
|
|
||||||
generator<Func>& operator=(const generator<Func> &y) = default;
|
|
||||||
generator(generator<Func> &&y) = default;
|
generator(generator<Func> &&y) = default;
|
||||||
generator(const generator<Func> &y) = default;
|
generator(const generator<Func> &y) = default;
|
||||||
|
|
||||||
bool is_terminated() const noexcept {
|
constexpr bool is_terminated() const noexcept {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,11 +408,13 @@ inline filteror<typename std::decay<Gen>::type, typename std::decay<Pred>::type>
|
|||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
|
template<typename ...Ts>
|
||||||
|
using tuple_cat_t = decltype(std::tuple_cat(std::declval<Ts>()...));
|
||||||
|
|
||||||
template<typename Tp, int n>
|
template<typename Tp, int n>
|
||||||
struct repeat_tuple {
|
struct repeat_tuple {
|
||||||
static_assert(n > 0, "");
|
static_assert(n > 0, "");
|
||||||
using type = decltype(std::tuple_cat(std::declval<std::tuple<Tp>>()
|
using type = tuple_cat_t<std::tuple<Tp>, typename repeat_tuple<Tp, n - 1>::type>;
|
||||||
, std::declval<typename repeat_tuple<Tp, n - 1>::type>()));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Tp>
|
template<typename Tp>
|
||||||
@ -517,8 +524,6 @@ inline auto uniform_ints(Tval &&l, Tval &&r) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
struct require_unique_t {} require_unique;
|
|
||||||
|
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
template<typename Tval, typename Engine>
|
template<typename Tval, typename Engine>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user