Terminal++ 3.1.0.4
A C++ library for interacting with ANSI terminal windows
Loading...
Searching...
No Matches
for_each_in_region.hpp
1#pragma once
2
3#include "terminalpp/core.hpp"
4#include "terminalpp/element.hpp"
5#include "terminalpp/rectangle.hpp"
6
7#include <concepts> // IWYU pragma: keep
8
9namespace terminalpp {
10
11template <typename TwoDimensionalContainer>
12concept element_container = requires(TwoDimensionalContainer tdc) {
13 {
14 tdc[terminalpp::coordinate_type{}][terminalpp::coordinate_type{}]
15 } -> std::convertible_to<terminalpp::element>;
16};
17
18//* =========================================================================
21//* =========================================================================
22void for_each_in_region(
23 element_container auto &&container,
24 rectangle const &region,
25 std::invocable<element &, coordinate_type, coordinate_type> auto &&callable)
26{
27 for (auto row = region.origin_.y_;
28 row < region.origin_.y_ + region.size_.height_;
29 ++row)
30 {
31 for (auto column = region.origin_.x_;
32 column < region.origin_.x_ + region.size_.width_;
33 ++column)
34 {
35 callable(container[column][row], column, row);
36 }
37 }
38}
39
40} // namespace terminalpp
Definition for_each_in_region.hpp:12
A class that represents a rectangle in space.
Definition rectangle.hpp:15
terminalpp::extent size_
The size (amount the rectangle extends right and down) of the rectangle.
Definition rectangle.hpp:45
terminalpp::point origin_
The origin (top-left point) of the rectangle.
Definition rectangle.hpp:41