blob: f787d3b04d840c4d45905365af066f0e5439831f [file] [log] [blame]
halcanary32875882016-08-16 09:36:23 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef SkEnumOperators_DEFINED
8#define SkEnumOperators_DEFINED
9
10#include "SkTLogic.h"
11
12namespace skstd {
13template <typename T> struct is_bitmask_enum : std::false_type {};
14}
15
16template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator|(E l, E r) {
17 using U = skstd::underlying_type_t<E>;
18 return static_cast<E>(static_cast<U>(l) | static_cast<U>(r));
19}
20
21template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator|=(E& l, E r) {
22 return l = l | r;
23}
24
25template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) operator&(E l, E r) {
26 using U = skstd::underlying_type_t<E>;
27 return static_cast<E>(static_cast<U>(l) & static_cast<U>(r));
28}
29
30template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) operator&=(E& l, E r) {
31 return l = l & r;
32}
33
34#endif // SkEnumOperators_DEFINED