Created
December 20, 2024 09:07
-
-
Save flomnes/c6c1045300aacd2d1871823804133452 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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