https://github.com/serpent7776/any_of
A library to compare value against many values.
https://github.com/serpent7776/any_of
compare cplusplus library operator
Last synced: about 1 month ago
JSON representation
A library to compare value against many values.
- Host: GitHub
- URL: https://github.com/serpent7776/any_of
- Owner: serpent7776
- Created: 2021-05-24T19:04:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-31T16:18:34.000Z (almost 5 years ago)
- Last Synced: 2025-12-26T19:37:19.435Z (6 months ago)
- Topics: compare, cplusplus, library, operator
- Language: C++
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# any_of
## Introduction
A simple library that lets you compare a value against many values using one operator.
E.g.
```c++
x == srp::any_of(1, 2, 3, 4);
```
is equivalent to:
```c++
x == 1 || x == 2 || x == 3 || x == 4;
```
Besides `any_of`, library also provides `none_of`, `all_of` and `one_of`. All of them override `operator==` in an expected way:
`x == srp::none_of(1, 2, 3)` is equivalent to `x != 1 && x != 2 && x != 3`
`x == srp::all_of(1, 2, 3)` is equivalent to `x == 1 && x == 2 && x == 3`
`x == srp::one_of(1, 2, 3)` is equivalent to `(x == 1) + (x == 2) + (x == 3) == 1`
## Custom functions
In addition to these functions, you can define your own functions with custom behaviour using `srp::make_custom_of`. It is a function template taking operator structs defining operators that should be available and return a lambda that can be called just like `srp::any_of`.
Operator struct should define an operator as a friend function.
Library provides `srp::EqOp` that provides `operator==` and `srp::NeqOp` that provides `operator!=`.