Skip to content

Instantly share code, notes, and snippets.

@flomnes
Created December 20, 2024 09:07
Show Gist options
  • Save flomnes/c6c1045300aacd2d1871823804133452 to your computer and use it in GitHub Desktop.
Save flomnes/c6c1045300aacd2d1871823804133452 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <vector>
static bool operator<=(const std::vector<double>& v, const double c)
{
return std::ranges::all_of(v, [&c](const double& e) { return e <= c; });
}
static bool operator>=(const std::vector<double>& v, const double c)
{
return std::ranges::all_of(v, [&c](const double& e) { return e >= c; });
}
#include <cassert>
int main()
{
const std::vector<double> V{1, 2, 3};
// operator<=
assert(V <= 4);
assert(V <= 3);
assert(!(V <= 2));
// operator>=
assert(V >= 0);
assert(!(V >= 5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment