blob: f787d3b04d840c4d45905365af066f0e5439831f (
plain)
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
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkEnumOperators_DEFINED
#define SkEnumOperators_DEFINED
#include "SkTLogic.h"
namespace skstd {
template <typename T> struct is_bitmask_enum : std::false_type {};
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator|(E l, E r) {
using U = skstd::underlying_type_t<E>;
return static_cast<E>(static_cast<U>(l) | static_cast<U>(r));
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator|=(E& l, E r) {
return l = l | r;
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator&(E l, E r) {
using U = skstd::underlying_type_t<E>;
return static_cast<E>(static_cast<U>(l) & static_cast<U>(r));
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator&=(E& l, E r) {
return l = l & r;
}
#endif // SkEnumOperators_DEFINED
|