From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- lib/collections.hpp | 159 ---------------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 lib/collections.hpp (limited to 'lib/collections.hpp') diff --git a/lib/collections.hpp b/lib/collections.hpp deleted file mode 100644 index 8f5a43d..0000000 --- a/lib/collections.hpp +++ /dev/null @@ -1,159 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -template -concept SequentialCollection = requires(T c) { - { - c.size() - } -> std::integral; - { - c.data() - } -> std::same_as; - }; -template -concept IterableCollection = std::is_same_v().begin()), decltype(std::declval().end())>; - -template -[[nodiscard]] constexpr std::array -operator+(const std::array & a, const std::array & b) -{ - std::array r; - auto out = r.begin(); - out = std::copy(a.begin(), a.end(), out); - std::copy(b.begin(), b.end(), out); - return r; -} - -template -[[nodiscard]] constexpr std::array, first * second> -operator*(const std::array & a, const std::array & b) -{ - std::array, first * second> r; - auto out = r.begin(); - for (const auto & ae : a) { - for (const auto & be : b) { - *out++ = {ae, be}; - } - } - return r; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::array & in, auto && f) -{ - std::array out; - - for (auto outitr = out.begin(); const auto & v : in) { - *outitr++ = f(v); - } - return out; -} - -constexpr auto & -operator*=(IterableCollection auto & in, auto && f) -{ - for (auto & v : in) { - f(v); - } - return in; -} - -template typename C, typename... T> - requires IterableCollection> -[[nodiscard]] constexpr auto -operator*(const C & in, auto && f) -{ - C out; - if constexpr (requires { out.reserve(in.size()); }) { - out.reserve(in.size()); - } - - std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); - return out; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::span in, auto && f) -{ - std::array())), N> out; - - std::transform(in.begin(), in.end(), out.begin(), f); - return out; -} - -template -[[nodiscard]] constexpr auto -operator*(const std::span in, auto && f) -{ - std::vector()))> out; - - out.reserve(in.size()); - std::transform(in.begin(), in.end(), std::inserter(out, out.end()), f); - return out; -} - -template -constexpr auto & -operator+=(std::vector & in, std::vector && src) -{ - in.reserve(in.size() + src.size()); - std::move(src.begin(), src.end(), std::back_inserter(in)); - return in; -} - -template -[[nodiscard]] constexpr auto -operator+(const std::vector & in, Vn && vn) -{ - auto out(in); - out.emplace_back(std::forward(vn)); - return out; -} - -template typename Direction = std::plus, typename T = unsigned int> -[[nodiscard]] static auto -vectorOfN(std::integral auto N, T start = {}, T step = 1) -{ - std::vector v; - v.resize(N); - std::generate_n(v.begin(), N, [&start, step, adj = Direction {}]() { - return std::exchange(start, adj(start, step)); - }); - return v; -} - -template typename Rtn = std::vector, IterableCollection In> -[[nodiscard]] auto -materializeRange(In && in) -{ - return Rtn(in.begin(), in.end()); -} - -template typename Rtn = std::vector, typename In> -[[nodiscard]] auto -materializeRange(const std::pair & in) -{ - return Rtn(in.first, in.second); -} - -template struct pair_range { - constexpr auto & - begin() const noexcept - { - return pair.first; - } - constexpr auto & - end() const noexcept - { - return pair.second; - } - const std::pair & pair; -}; -template pair_range(std::pair) -> pair_range; -- cgit v1.2.3