-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisin.h
56 lines (44 loc) · 1.33 KB
/
isin.h
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
/*
Copyright 2018 Krzysztof Karbowiak
*/
#ifndef ISIN_H__DDK
#define ISIN_H__DDK
#include <initializer_list>
#include <algorithm>
#define is_in(...) == isin_internal::is_in_get(__VA_ARGS__)
#define is_not_in(...) != isin_internal::is_in_get(__VA_ARGS__)
namespace isin_internal
{
template<class C>
class is_in_check
{
public:
is_in_check(C const & args)
: m_args(args)
{
}
template<typename T>
friend bool operator==(T const & lhs, is_in_check<C> const & rhs)
{
return std::any_of(rhs.m_args.begin(), rhs.m_args.end(), [&](T const & v){ return (lhs == v); });
}
template<typename T>
friend bool operator!=(T const & lhs, is_in_check<C> const & rhs)
{
return std::none_of(rhs.m_args.begin(), rhs.m_args.end(), [&](T const & v){ return (lhs == v); });
}
private:
C const & m_args;
};
template<class C>
inline is_in_check<C> is_in_get(C const & args)
{
return is_in_check<C>(args);
}
template<typename T>
inline is_in_check<std::initializer_list<T>> is_in_get(std::initializer_list<T> const & args)
{
return is_in_check<std::initializer_list<T>>(args);
}
}
#endif /* ISIN_H__DDK */