diff --git a/libvmake/examples/discarding.cpp b/libvmake/examples/discarding.cpp new file mode 100644 index 0000000..5afa500 --- /dev/null +++ b/libvmake/examples/discarding.cpp @@ -0,0 +1,6 @@ +#include "../vmake.hpp" +using namespace std; + +int main() { + vmake::outputln(cout, " ", vmake::discard_n(vmake::range(1, 10), 2)); +} diff --git a/libvmake/vmake.hpp b/libvmake/vmake.hpp index fe24cc6..b7bf761 100644 --- a/libvmake/vmake.hpp +++ b/libvmake/vmake.hpp @@ -31,8 +31,11 @@ using std::apply; using nonstd::optional; -template struct add_const_t { using type = const T; }; -template constexpr typename add_const_t::type& as_const(T& t) noexcept { return t; } +template +constexpr typename std::add_const::type& as_const(T& t) noexcept { + return t; +} + template void as_const(const T&&) = delete; namespace details { @@ -42,7 +45,7 @@ decltype(auto) apply_helper(Func &&f, Tuple &&t, std::index_sequence) return f(std::get(std::forward(t))...); } -} +} // namespace details template decltype(auto) apply(Func &&f, Tuple &&t) { @@ -61,7 +64,7 @@ template auto is_sequence_helper(char) -> decltype( std::declval()() , typename std::enable_if::type>().is_terminated()) + std::declval::type>().is_terminated()) , bool>::value, int>::type{0} , typename std::enable_if()()) , typename T::result>::value, int>::type{0} @@ -331,7 +334,7 @@ inline auto repeat(Tval &&x) { } template -inline auto repeat_n(Tval &&x, size_t n) { +inline decltype(auto) repeat_n(Tval &&x, size_t n) { return take(repeat(std::forward(x)), n); } @@ -482,11 +485,11 @@ namespace details { //template //using tuple_cat_t = decltype(std::tuple_cat(std::declval()...)); -template +template auto repeat_tuple_builder(std::index_sequence seq) -> std::tuple::type...>; -template +template struct repeat_tuple_t { using type = decltype(repeat_tuple_builder(std::make_index_sequence())); }; @@ -496,10 +499,10 @@ inline auto group_builder(Gen &g, std::index_sequence seq) { auto val = std::array{ (void(index), g())... }; - return std::make_tuple(std::move(val[index])...); + return std::make_tuple(std::move(std::get(val))...); } -template +template struct grouper { static_assert(n > 0, ""); using result = typename repeat_tuple_t::type; @@ -522,11 +525,17 @@ struct grouper { } -template +template inline auto group(Gen &&g) { return details::grouper::type, n>(std::forward(g)); } +template +inline decltype(auto) discard_n(Gen &&g, size_t n) { + for (size_t i = 0; i < n; ++i) g(); + return std::forward(g); +} + namespace rng { inline auto make_seed() { @@ -599,7 +608,7 @@ struct unique_ints_sequence { std::uniform_int_distribution dis; bool halfed; std::unordered_set used; - std::vector rest; + std::vector rest; unique_ints_sequence(Engine &&e, Tval &&l, Tval &&r) : l(std::forward(l)) , r(std::forward(r)), rng(std::forward(e))