From 5fb57643791d0400e4aa75ddc3ea45acba9b92d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me?= Date: Sat, 30 Mar 2019 11:48:51 +0100 Subject: [PATCH] Added helper functions in utils.hpp --- utils.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils.hpp b/utils.hpp index 3b74a0d..14088ab 100644 --- a/utils.hpp +++ b/utils.hpp @@ -2,12 +2,17 @@ #define DEF_utils #include +#include #define PRINT_VAR(x) std::cout << #x << "\t= " << (x) << "\n" #define PRINT_VEC(x); {std::cout << #x << "\t= "; \ for(unsigned int i_print_vec = 0 ; i_print_vec < (x).size() ; i_print_vec++) \ std::cout << (x)[i_print_vec] << "\t"; \ std::cout << "\n";} +#define PRINT_STR(x) std::cout << (x) << "\n" + +template auto min(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(a) : T(b); } +template auto max(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(b) : T(a); } template class C, class... Args> std::ostream& operator<<(std::ostream& os, const C& objs) @@ -17,4 +22,15 @@ std::ostream& operator<<(std::ostream& os, const C& objs) return os; } +/// Convenience template class to do StdPairValueCatcher(a, b) = someFunctionThatReturnsAnStdPair() +/// Instead of doing a = std::get<0>(result_from_function), b = std::get<1>(result_from_function) +template +struct StdPairValueCatcher +{ + A & a; + B & b; + StdPairValueCatcher(A & a_, B & b_) : a(a_), b(b_) {} + std::pair const& operator=(std::pair const& p) {a = std::get<0>(p); b = std::get<1>(p); return p; } +}; + #endif