16 #error no need to expose this header to Swig
20 #ifndef BORNAGAIN_BASE_UTIL_ALGORITHMS_H
21 #define BORNAGAIN_BASE_UTIL_ALGORITHMS_H
35 constexpr
double eps = std::numeric_limits<double>::epsilon();
36 return std::abs(a - b) <= eps * std::max(eps, (std::abs(a) + std::abs(b)) / 2);
40 template <
typename Evaluator,
typename Iterator>
41 double min_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
44 template <
typename Evaluator,
typename Iterator>
45 double max_value(
const Iterator& begin,
const Iterator& end,
const Evaluator& evaluate);
49 std::vector<T>
concat(
const std::vector<T>& v1,
const std::vector<T>& v2);
57 template <
typename Evaluator,
typename Iterator>
59 const Evaluator& evaluate)
62 double result = evaluate(*begin);
65 result = std::min(result, evaluate(*it));
69 template <
typename Evaluator,
typename Iterator>
71 const Evaluator& evaluate)
74 double result = evaluate(*begin);
77 result = std::max(result, evaluate(*it));
84 std::vector<T> v = v1;
85 v.insert(v.end(), v2.begin(), v2.end());
Defines the macro ASSERT.
#define ASSERT(condition)
Some additions to standard library algorithms.
std::vector< T > concat(const std::vector< T > &v1, const std::vector< T > &v2)
Returns the concatenation of two std::vectors.
double max_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the maximum value of function evaluate as applied to the elements of an iterator range.
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
double min_value(const Iterator &begin, const Iterator &end, const Evaluator &evaluate)
Returns the minimum value of function evaluate as applied to the elements of an iterator range.