Skip to content

Commit

Permalink
minmax() is better named range(). Leave minmax in place, too
Browse files Browse the repository at this point in the history
  • Loading branch information
sebjameswml committed Nov 2, 2023
1 parent c810b4c commit c2f491b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions morph/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ namespace morph {
return morph::range<S>(*mm.first, *mm.second);
}

//! Return the range of the vec (the min and max values of the vec)
morph::range<S> range() const
{
auto mm = std::minmax_element (this->begin(), this->end());
return morph::range<S>(*mm.first, *mm.second);
}

//! Return true if any element is zero
bool has_zero() const
{
Expand Down
8 changes: 7 additions & 1 deletion morph/vvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,13 @@ namespace morph {
//! pass 'true' as the template arg, then you can test for nans, and return the min/max of
//! the rest of the numbers
template<bool test_for_nans = false>
morph::range<S> minmax() const
morph::range<S> minmax() const { return this->range<test_for_nans>(); }

//! Return the range of values in the vvec (the min and max values). If you pass 'true' as
//! the template arg, then you can test for nans, and return the min/max of the rest of the
//! numbers
template<bool test_for_nans = false>
morph::range<S> range() const
{
morph::range<S> r;
if constexpr (test_for_nans) {
Expand Down

0 comments on commit c2f491b

Please sign in to comment.