-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorigin_to_compare.hpp
71 lines (58 loc) · 1.59 KB
/
origin_to_compare.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
template <typename T>
class origin_to_compare
{
public:
template <typename... Args>
constexpr bool any_of(Args const &...args)
{
return any_of_impl(args...);
}
template <typename... Args>
constexpr bool none_of(Args const &...args)
{
return none_of_impl(args...);
}
origin_to_compare(origin_to_compare const &other) = delete;
origin_to_compare &operator=(origin_to_compare const &other) = delete;
private:
constexpr origin_to_compare(T const &v) : m_value(v)
{
}
template <typename U>
friend constexpr origin_to_compare<U> is(U const &v);
template <typename U, typename... Args>
constexpr bool any_of_impl(U const &first, Args const &...others)
{
return first == m_value ? true : any_of_impl(others...);
}
template <typename U>
constexpr bool any_of_impl(U const &other)
{
return m_value == other;
}
template <typename U, typename... Args>
constexpr bool none_of_impl(U const &first, Args const &...others)
{
return first == m_value ? false : none_of_impl(others...);
}
template <typename U>
constexpr bool none_of_impl(U const &other)
{
return m_value != other;
}
private:
T const &m_value;
};
template <typename T>
constexpr origin_to_compare<T> is(T const &v)
{
return origin_to_compare<T>(v);
}
// int main(int argc, const char *argv[])
// {
// static_assert(is(5).any_of(1, 2, 3, 4, 5));
// static_assert(is(5).none_of(1, 2, 3, 4, 6));
// static_assert(!is(5).none_of(1, 2, 3, 4, 5));
// return 0;
// }