#pragma once #include template class FIFO { private: size_t produce = 0; size_t consume = 0; bool empty = true; T storage[N]; public: bool push(T x) { if(produce == consume && !empty) return false; storage[produce] = x; produce = (produce + 1) % N; empty = false; return true; } std::optional pull() { if(empty) return std::nullopt; T ret = storage[consume]; consume = (consume + 1) % N; if(produce == consume) empty = true; return ret; } };