GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
enum.h
Go to the documentation of this file.
1// Copyright (c) 2025 Clarisma / GeoDesk contributors
2// SPDX-License-Identifier: LGPL-3.0-only
3
4#pragma once
5#include <type_traits>
6
7#define CLARISMA_ENUM_FLAGS(EnumType) \
8constexpr EnumType operator|(EnumType a, EnumType b) noexcept \
9{ \
10using U = std::underlying_type_t<EnumType>; \
11return static_cast<EnumType>(static_cast<U>(a) | static_cast<U>(b)); \
12} \
13constexpr EnumType operator&(EnumType a, EnumType b) noexcept \
14{ \
15using U = std::underlying_type_t<EnumType>; \
16return static_cast<EnumType>(static_cast<U>(a) & static_cast<U>(b)); \
17} \
18constexpr EnumType& operator|=(EnumType& a, EnumType b) noexcept \
19{ \
20a = a | b; \
21return a; \
22} \
23constexpr EnumType& operator&=(EnumType& a, EnumType b) noexcept \
24{ \
25a = a & b; \
26return a; \
27} \
28constexpr EnumType operator~(EnumType a) noexcept \
29{ \
30 return static_cast<EnumType>(~static_cast<uint64_t>(a)); \
31} \
32constexpr auto has(EnumType a, EnumType b) noexcept \
33{ \
34return static_cast<bool>(a & b); \
35} \
36constexpr auto hasAny(EnumType a, EnumType b) noexcept \
37{ \
38 return static_cast<bool>(a & b); \
39} \
40constexpr auto hasAll(EnumType a, EnumType b) noexcept \
41{ \
42 return (a & b) == b; \
43} \
44
45
46/*
47constexpr bool operator bool(EnumType e) noexcept \
48{ \
49 return static_cast<uint64_t>(e) != 0; \
50}
51*/