2020-12-10 19:26:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace ss {
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// all except
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T, auto... Values>
|
|
|
|
struct ax {
|
2020-12-26 00:46:42 +01:00
|
|
|
private:
|
|
|
|
template <auto X, auto... Xs>
|
|
|
|
bool ss_valid_impl(const T& x) const {
|
|
|
|
if constexpr (sizeof...(Xs) != 0) {
|
|
|
|
return x != X && ss_valid_impl<Xs...>(x);
|
2020-12-10 19:26:56 +01:00
|
|
|
}
|
2020-12-26 00:46:42 +01:00
|
|
|
return x != X;
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
|
2020-12-26 00:46:42 +01:00
|
|
|
public:
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return ss_valid_impl<Values...>(value);
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
|
2020-12-26 00:46:42 +01:00
|
|
|
const char* error() const {
|
|
|
|
return "value excluded";
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// none except
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T, auto... Values>
|
|
|
|
struct nx {
|
2020-12-26 00:46:42 +01:00
|
|
|
private:
|
|
|
|
template <auto X, auto... Xs>
|
|
|
|
bool ss_valid_impl(const T& x) const {
|
|
|
|
if constexpr (sizeof...(Xs) != 0) {
|
|
|
|
return x == X || ss_valid_impl<Xs...>(x);
|
2020-12-10 19:26:56 +01:00
|
|
|
}
|
2020-12-26 00:46:42 +01:00
|
|
|
return x == X;
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
|
2020-12-26 00:46:42 +01:00
|
|
|
public:
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return ss_valid_impl<Values...>(value);
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
|
2020-12-26 00:46:42 +01:00
|
|
|
const char* error() const {
|
|
|
|
return "value excluded";
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
};
|
|
|
|
|
2021-01-03 15:38:07 +01:00
|
|
|
////////////////
|
|
|
|
// greater than or equal to
|
|
|
|
// greater than
|
|
|
|
// less than
|
|
|
|
// less than or equal to
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T, auto N>
|
|
|
|
struct gt {
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value > N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, auto N>
|
|
|
|
struct gte {
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value >= N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, auto N>
|
|
|
|
struct lt {
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value < N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, auto N>
|
|
|
|
struct lte {
|
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value <= N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-10 19:26:56 +01:00
|
|
|
////////////////
|
|
|
|
// in range
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T, auto Min, auto Max>
|
|
|
|
struct ir {
|
2020-12-26 00:46:42 +01:00
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value >= Min && value <= Max;
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// out of range
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T, auto Min, auto Max>
|
|
|
|
struct oor {
|
2020-12-26 00:46:42 +01:00
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return value < Min || value > Max;
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////
|
|
|
|
// non empty
|
|
|
|
////////////////
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct ne {
|
2020-12-26 00:46:42 +01:00
|
|
|
bool ss_valid(const T& value) const {
|
|
|
|
return !value.empty();
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
|
2020-12-26 00:46:42 +01:00
|
|
|
const char* error() const {
|
|
|
|
return "empty field";
|
|
|
|
}
|
2020-12-10 19:26:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* ss */
|