Extract range_t to utility header.

This commit is contained in:
Jared Boone 2016-01-27 12:09:36 -08:00
parent c761d3aaa8
commit 018b54c711
2 changed files with 20 additions and 18 deletions

View file

@ -25,6 +25,7 @@
#include <type_traits>
#include <cstdint>
#include <cstddef>
#include <algorithm>
#include <complex>
#include <memory>
@ -70,6 +71,23 @@ inline float magnitude_squared(const std::complex<float> c) {
return r2 + i2;
}
template<class T>
struct range_t {
const T minimum;
const T maximum;
const T& clip(const T& value) const {
return std::max(std::min(value, maximum), minimum);
}
void reset_if_outside(T& value, const T& reset_value) const {
if( (value < minimum ) ||
(value > maximum ) ) {
value = reset_value;
}
}
};
namespace std {
/*! Stephan T Lavavej (STL!) implementation of make_unique, which has been accepted into the C++14 standard.