Compare commits

...

2 Commits

Author SHA1 Message Date
3deeedc7aa add example random_even.cpp 2023-07-23 15:24:35 +08:00
753b474376 strict is_sequence_t 2023-07-23 15:24:13 +08:00
2 changed files with 33 additions and 20 deletions

View File

@ -0,0 +1,10 @@
#include "../vmake.hpp"
#include <iostream>
using namespace std;
int main() {
vmake::outputln_n(cout, 1000, " ", vmake::filter(
vmake::rng::uniform_ints(vmake::require_unique, 1, 10000),
[](auto x) { return x % 2 == 0; }));
}

View File

@ -19,24 +19,6 @@ struct sequence_terminated_error : std::exception {
}
};
namespace details {
template<typename T>
auto is_sequence_helper(char) -> decltype(
std::declval<T>()()
, std::declval<T>().is_terminated()
, typename std::enable_if<std::is_same<decltype(std::declval<T>()())
, typename T::result>::value, int>::type()
, std::true_type{});
template<typename T>
auto is_sequence_helper(int) -> std::false_type;
}
template<typename T>
using is_sequence_t = decltype(details::is_sequence_helper<T>(' '));
namespace polyfill {
#if __cplusplus >= 201703L
@ -75,6 +57,26 @@ decltype(auto) apply(Func &&f, Tuple &&t) {
namespace details {
template<typename T>
auto is_sequence_helper(char) -> decltype(
std::declval<T>()()
, typename std::enable_if<std::is_same<decltype(
std::declval<typename polyfill::add_const_t<T>::type>().is_terminated())
, bool>::value, int>::type{0}
, typename std::enable_if<std::is_same<decltype(std::declval<T>()())
, typename T::result>::value, int>::type{0}
, std::true_type{});
template<typename T>
auto is_sequence_helper(int) -> std::false_type;
}
template<typename T>
using is_sequence_t = decltype(details::is_sequence_helper<T>(' '));
namespace details {
template<typename T>
struct iota_sequence {
using result = T;
@ -608,7 +610,7 @@ struct unique_ints_sequence {
}
auto operator()() {
if (!halfed && Tval{(used.size() + 1) * 2} >= r - l + 1) {
if (!halfed && (used.size() + 1) * 2 - (r - l + 1) >= 0) {
for (Tval i = l; i <= r; ++i) {
if (!used.count(i)) rest.push_back(i);
}
@ -741,6 +743,7 @@ namespace _checks {
using empty_sequence_int = decltype(nothing<int>());
/*
static_assert(is_sequence_t<empty_sequence_int>::value
&& is_sequence_t<decltype(take(empty_sequence_int{}, 1))>::value
&& is_sequence_t<decltype(group<20>(empty_sequence_int{}))>::value
@ -748,7 +751,7 @@ static_assert(is_sequence_t<empty_sequence_int>::value
&& !is_sequence_t<int>::value
&& !is_sequence_t<std::less<int>>::value
, "compile-time self-checking failed(try upgrading your compiler).");
*/
} // namespace _checks
} // namespace vmake