/************************************************************************* ** algorithm.hpp ** ** ** ** This file is part of dvisvgm -- a fast DVI to SVG converter ** ** Copyright (C) 2005-2025 Martin Gieseking ** ** ** ** This program is free software; you can redistribute it and/or ** ** modify it under the terms of the GNU General Public License as ** ** published by the Free Software Foundation; either version 3 of ** ** the License, or (at your option) any later version. ** ** ** ** This program is distributed in the hope that it will be useful, but ** ** WITHOUT ANY WARRANTY; without even the implied warranty of ** ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** ** GNU General Public License for more details. ** ** ** ** You should have received a copy of the GNU General Public License ** ** along with this program; if not, see . ** *************************************************************************/ #pragma once #include #include #include namespace algo { template T accumulate (const Container &c, T init, BinaryOp op) { return std::accumulate(std::begin(c), std::end(c), std::move(init), op); } template bool any_of (const Container &c, UnaryOp op) { return std::any_of(std::begin(c), std::end(c), op); } template bool all_of (const Container &c, UnaryOp op) { return std::all_of(std::begin(c), std::end(c), op); } template bool none_of (const Container &c, UnaryOp op) { return std::none_of(std::begin(c), std::end(c), op); } template bool binary_search (const Container &c, T val, Compare cmp) { return std::binary_search(std::begin(c), std::end(c), std::move(val), cmp); } template OutputIt copy (const Container &c, OutputIt out) { return std::copy(std::begin(c), std::end(c), out); } template OutputIt copy_if (const Container &c, OutputIt out, UnaryOp op) { return std::copy_if(std::begin(c), std::end(c), out, op); } template size_t count_if (const Container &c, UnaryOp op) { return std::count_if(std::begin(c), std::end(c), op); } template auto erase_if (Container &c, UnaryOp op) -> decltype(std::begin(std::declval())) { return c.erase(std::remove_if(std::begin(c), std::end(c), op), std::end(c)); } template auto find (Container &c, const T &val) -> decltype(std::begin(std::declval())) { return std::find(std::begin(c), std::end(c), val); } template auto find_if (Container &c, UnaryOp op) -> decltype(std::begin(std::declval())) { return std::find_if(std::begin(c), std::end(c), op); } template void generate (Container &c, Generator generator) { std::generate(std::begin(c), std::end(c), generator); } template auto lower_bound (Container &c, const T &val) -> decltype(std::begin(std::declval())) { return std::lower_bound(std::begin(c), std::end(c), val); } template auto lower_bound (Container &c, const T &val, Compare cmp) -> decltype(std::begin(std::declval())) { return std::lower_bound(std::begin(c), std::end(c), val, cmp); } template auto max_element (Container &c) -> decltype(std::begin(std::declval())) { return std::max_element(std::begin(c), std::end(c)); } template void sort (Container &c, Compare cmp) { return std::sort(std::begin(c), std::end(c), cmp); } template OutputIt transform (const Container &c, OutputIt out, UnaryOp op) { return std::transform(std::begin(c), std::end(c), out, op); } } // namespace algo