From 364c1ecd8703dadaaa9c7479335e469b153a1be0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jan 2018 12:28:25 +0100 Subject: compat: split/cleanup util.hpp Some of the headers are clearly useless. Remove them. Move what's inside util.hpp into separate headers. Adjust usages. Will remove util.hpp. --- compat/functional.hpp | 87 --------------------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 compat/functional.hpp (limited to 'compat/functional.hpp') diff --git a/compat/functional.hpp b/compat/functional.hpp deleted file mode 100644 index dcba0538..00000000 --- a/compat/functional.hpp +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include "value-templates.hpp" - -#include -#include -#include -#include - -namespace functools -{ - -template -struct reserver_ -{ - static inline void maybe_reserve_space(seq_&, unsigned) - { - //qDebug() << "nada"; - } -}; - -template -struct reserver_().reserve(0u), (void)0)> -{ - 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 value_type = std::decay_t::value_type>; - using ret_type = std::decay_t()))>; - - std::vector ret; - auto 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 = std::decay_t; - using value_type = std::decay_t::value_type>; - using fun_ret_type = decltype(fun(std::declval())); - static_assert(is_convertible_v, "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; -} -- cgit v1.2.3