This commit is contained in:
2024-09-02 14:12:42 -07:00
parent 1fd2a6b7ff
commit 9aa821376c
4 changed files with 148 additions and 5 deletions

View File

@@ -80,6 +80,7 @@ auto operator*=(Coord &, std::int64_t) -> Coord &;
template<>
struct std::hash<aocpp::Coord>
{
using is_transparent = void;
auto operator()(aocpp::Coord const& c) const noexcept -> std::size_t {
std::hash<std::int64_t> h;
return h(c.x) ^ h(c.y);

View File

@@ -1,11 +1,12 @@
#ifndef AOCPP_GRID_HPP_
#define AOCPP_GRID_HPP_
#include <concepts>
#include <iostream>
#include <vector>
#include <utility>
#include <type_traits>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
#include <aocpp/Coord.hpp>
@@ -62,8 +63,14 @@ struct Grid {
return result;
}
template <typename F>
auto each(F f = F{}) const {
/**
* @brief Apply the callback function across all elements of the grid.
*
* @tparam F Type of callback
* @param f Callback function
*/
template <std::invocable<Coord, char> F>
auto each(F f = F{}) const -> void {
auto const h = rows.size();
for (std::size_t y = 0; y < h; y++) {
auto const& row = rows[y];