Skip to content
Snippets Groups Projects
Commit 75e9b183 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add NaNHelper utility

The aim of this helper is to allow to print signaling NaN.
This should help to debug uninitialized matrices of vectors values
while printing them.
parent a6b6f5af
No related branches found
No related tags found
1 merge request!105Add NaNHelper utility
This commit is part of merge request !105. Comments created here will be created in the context of that merge request.
#ifndef NAN_HELPER_HPP
#define NAN_HELPER_HPP
#include <cmath>
#include <iostream>
#include <type_traits>
template <typename T>
class NaNHelper
{
private:
const T& m_t;
public:
friend std::ostream&
operator<<(std::ostream& os, const NaNHelper<T>& helper)
{
if constexpr (std::is_arithmetic_v<T>) {
if (std::isnan(helper.m_t)) {
os << "nan";
} else {
os << helper.m_t;
}
} else {
os << helper.m_t;
}
return os;
}
NaNHelper(const T& t) : m_t{t} {}
NaNHelper(NaNHelper&&) = delete;
NaNHelper(const NaNHelper&) = delete;
NaNHelper() = delete;
~NaNHelper() = default;
};
#endif // NAN_HELPER_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment