From 6aed2c58e85f16f3b26a7d4238c810ac8520873b Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 23 May 2023 20:21:20 +0200 Subject: [PATCH] auxiliary function atmod --- hyper.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hyper.h b/hyper.h index a120a713..1c4df2a5 100644 --- a/hyper.h +++ b/hyper.h @@ -884,6 +884,18 @@ const typename Map::mapped_type *at_or_null(const Map& map, const Key& key) { return (it == map.end()) ? nullptr : &it->second; } +int gmod(int i, int j); + +// vector::at(i) modulo its size (const version) +template const T& atmod(const vector& container, int index) { + return container[gmod(index, isize(container))]; + } + +// vector::at(i) modulo its size (non-const version) +template T& atmod(vector& container, int index) { + return container[gmod(index, isize(container))]; + } + namespace daily { extern bool on; extern int daily_id;