torognes / swarm

A robust and fast clustering method for amplicon-based studies
GNU Affero General Public License v3.0
121 stars 23 forks source link

macros for min() and max()? #155

Closed frederic-mahe closed 3 years ago

frederic-mahe commented 4 years ago

There's a std::min and std::max in C++. So, could these macros be removed?

#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif

#ifndef MAX
#define MAX(x,y) ((x)>(y)?(x):(y))
#endif

or do we need them for systems that do not implement the standard library? (eg.; Microsoft Windows); or because of a conflict between stdlib.h/cstdlib and the STL?

Bjarne Stroustrup recommends to use templates rather than macros, so in our case that would be:

#ifndef MIN
template<typename T>
inline const T& MIN(const T& x, const T& y)
{
  return (x<y)?x:y;
}
#endif

#ifndef MAX
template<typename T>
inline const T& MAX(const T& x, const T& y)
{
  return (x>y)?x:y;
}
#endif
torognes commented 4 years ago

It currently fails to compile on some platforms if MIN and MAX are removed.

frederic-mahe commented 3 years ago

Is this still the case or can we switch to using std::min and std::max? If not what are the offending platforms?

torognes commented 3 years ago

Replaced by std::min and std::max in commit 0420591b35b18618c5f307e231faca73ee1d2096.