osh.h

My personal stdc++ replacement
git clone git://git.oshgnacknak.de/osh.h.git
Log | Files | Refs

commit 3a782f6e23b2696322a848a7177414e1277516f6
parent 7743f77dfec8a722cbeba6aa6b87aa3e4a3903f1
Author: Oshgnacknak <osh@oshgnacknak.de>
Date:   Wed, 29 Dec 2021 17:53:35 +0100

Add min, max and panic

Diffstat:
Mosh.h | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/osh.h b/osh.h @@ -5,6 +5,12 @@ namespace osh { + template<typename T> + T min(T a, T b); + + template<typename T> + T max(T a, T b); + template<typename P, typename T> concept PrintableTo = requires(P p, T t) { print1(p, t); @@ -50,14 +56,29 @@ namespace osh { template<typename T> void print1(FILE* stream, const T& t); + + template<PrintableTo<Formatter>... Args> + [[noreturn]] void panic(Args... args); } #endif /* OSH_H */ #ifdef OSH_H_IMPLEMENTATION +#include <stdlib.h> + namespace osh { + template<typename T> + T min(T a, T b) { + return a < b ? a : b; + } + + template<typename T> + T max(T a, T b) { + return a > b ? a : b; + } + void print1(Formatter auto& fmt, const char* s) { fmt.format("%s", s); } @@ -135,6 +156,11 @@ namespace osh { print1(fmt, t); } + template<typename... Args> + void panic(Args... args) { + printp(ferr, args...); + exit(1); + } } #endif // OSH_H_IMPLEMENTATION