File: _flag_enum_operator_helpers.hh

package info (click to toggle)
notcurses 3.0.17%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,780 kB
  • sloc: ansic: 50,375; cpp: 17,808; python: 1,123; sh: 230; makefile: 35
file content (52 lines) | stat: -rw-r--r-- 2,060 bytes parent folder | download | duplicates (2)
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
#ifndef __NCPP_FLAG_ENUM_OPERATOR_HELPERS_H
#define __NCPP_FLAG_ENUM_OPERATOR_HELPERS_H

#include <type_traits>

#include "_helpers.hh"

namespace ncpp
{
#define DECLARE_ENUM_FLAG_OPERATORS(__enum_name__)                      \
	NCPP_API_EXPORT constexpr __enum_name__ operator& (__enum_name__ x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return __enum_name__ (static_cast<etype> (x) & static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__& operator&= (__enum_name__& x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return x = __enum_name__ (static_cast<etype> (x) & static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__ operator| (__enum_name__ x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return __enum_name__ (static_cast<etype> (x) | static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__& operator|= (__enum_name__& x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return x = __enum_name__ (static_cast<etype> (x) | static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__ operator^ (__enum_name__ x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return __enum_name__ (static_cast<etype> (x) ^ static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__& operator^= (__enum_name__& x, __enum_name__ y) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return x = __enum_name__ (static_cast<etype> (x) ^ static_cast<etype> (y)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__& operator~ (__enum_name__& x) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return x = __enum_name__ (~static_cast<etype> (x)); \
	} \
	NCPP_API_EXPORT constexpr __enum_name__ operator~ (__enum_name__ x) \
	{ \
		typedef std::underlying_type<__enum_name__>::type etype; \
		return __enum_name__ (~static_cast<etype> (x)); \
	}
}
#endif