summaryrefslogtreecommitdiff
path: root/include/mbgl/util/bitmask_operations.hpp
blob: 014fabdea254bb50b61cc9fffa60e560c96429b0 (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
#pragma once

#include <mbgl/util/traits.hpp>
#include <mbgl/util/util.hpp>

namespace mbgl {

template<typename Enum>
MBGL_CONSTEXPR Enum operator|(Enum a, Enum b) {
    static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
    return Enum(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}

template<typename Enum>
MBGL_CONSTEXPR Enum& operator|=(Enum& a, Enum b) {
    static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
    return (a = a | b);
}

template<typename Enum>
MBGL_CONSTEXPR bool operator&(Enum a, Enum b) {
    static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
    return bool(mbgl::underlying_type(a) & mbgl::underlying_type(b));
}

template<typename Enum>
MBGL_CONSTEXPR Enum operator~(Enum value) {
    static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
    return Enum(~mbgl::underlying_type(value));
}


} // namespace mbgl