any_of, all_of, and none_of for more succinct and readable predicates
C++ CMake
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status

smart_conditions is a C++11 library that lets you refactor repetitive and potentially unreadable/error-prone code:

// let some_string, a, b be std::string's
if (some_string == a || some_string == b || some_string == "foo")
    // ...

into something more readable and maintainable:

#include "smart_conditions.hpp"
using namespace smart_conditions;

// let some_string, a, b be std::string's
if (some_string == any_of (a, b, "foo")) // you can mix types as long as an operator accepting them exists
    // ...

without using initialiser_lists (that can't mix different types together), containers or iterators, without allocating memory, and without making unnecessary copies.

any_of, all_of, and none_of are provided, each one having its usual meaning. They can lie on either side of any of the following operators: == != > < >= <= || && ^.

And they can lie on both sides, as in:

// let a = "bar", b = "foo" be std::string's

if (all_of ("foo", "bar") == any_of (a, b, "asd")) // will evaluate as true
    // ...

Compile-time evaluation is also possible, as long as the operands are known at compile time:

static const int a = 1;

static_assert(a == any_of (1, 5, 7, 12), "...");