2019-03-28 16:38:50 +01:00
|
|
|
#ifndef DEF_utils
|
|
|
|
|
#define DEF_utils
|
|
|
|
|
|
|
|
|
|
#include <ostream>
|
2019-03-30 11:48:51 +01:00
|
|
|
#include <utility>
|
2019-03-28 16:38:50 +01:00
|
|
|
|
|
|
|
|
#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";}
|
2019-03-30 11:48:51 +01:00
|
|
|
#define PRINT_STR(x) std::cout << (x) << "\n"
|
|
|
|
|
|
|
|
|
|
template<typename T, typename T2> auto min(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(a) : T(b); }
|
|
|
|
|
template<typename T, typename T2> auto max(const T & a, const T2 & b) -> decltype(a | b) { return (a < b) ? T(b) : T(a); }
|
2019-03-28 16:38:50 +01:00
|
|
|
|
2019-04-01 16:18:34 +02:00
|
|
|
/// To be sure that floating point numbers won't be casted to integers in ::abs()...
|
|
|
|
|
template<typename T> T sureAbs(const T & x) { return (x < T(0)) ? -x : x; }
|
|
|
|
|
|
2019-03-28 16:38:50 +01:00
|
|
|
template<typename T, template<class,class...> class C, class... Args>
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const C<T,Args...>& objs)
|
|
|
|
|
{
|
|
|
|
|
for (auto const& obj : objs)
|
|
|
|
|
os << obj << ' ';
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 11:48:51 +01:00
|
|
|
/// Convenience template class to do StdPairValueCatcher(a, b) = someFunctionThatReturnsAnStdPair<A,B>()
|
|
|
|
|
/// Instead of doing a = std::get<0>(result_from_function), b = std::get<1>(result_from_function)
|
|
|
|
|
template<typename A, typename B>
|
|
|
|
|
struct StdPairValueCatcher
|
|
|
|
|
{
|
|
|
|
|
A & a;
|
|
|
|
|
B & b;
|
|
|
|
|
StdPairValueCatcher(A & a_, B & b_) : a(a_), b(b_) {}
|
|
|
|
|
std::pair<A, B> const& operator=(std::pair<A, B> const& p) {a = std::get<0>(p); b = std::get<1>(p); return p; }
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-28 16:38:50 +01:00
|
|
|
#endif
|