#pragma once #include #include #include namespace functools { constexpr void return_void(); template using remove_qualifiers = std::remove_reference_t>; template struct reserver_ { static inline void maybe_reserve_space(seq_&, unsigned) { //qDebug() << "nada"; } }; template struct reserver_().reserve(0u), return_void())> { static inline void maybe_reserve_space(seq_& seq, unsigned sz) { seq.reserve(sz); } }; template inline void maybe_reserve_space(seq_& seq, unsigned sz) { reserver_::maybe_reserve_space(seq, sz); } } // ns template struct constant final { using type = t; constexpr type operator()() const noexcept { return value_; } static constexpr type value = value_; constant() = delete; }; template auto map(F&& fun, const seq_& seq) { using seq_type = functools::remove_qualifiers; seq_type ret; std::back_insert_iterator it = std::back_inserter(ret); for (const auto& elt : seq) it = fun(elt); return ret; } template auto remove_if_not(F&& fun, const seq_& seq) { using namespace functools; using seq_type = remove_qualifiers; using value_type = typename std::iterator_traits()))>::value_type; using fun_ret_type = decltype(fun(std::declval())); static_assert(std::is_convertible::value, "must return bool"); seq_type ret; maybe_reserve_space(ret, seq.size()); std::back_insert_iterator it = std::back_inserter(ret); for (const value_type& elt : seq) if (fun(elt)) it = elt; return ret; }