-
Notifications
You must be signed in to change notification settings - Fork 6
/
EnumO.h
46 lines (39 loc) · 1.78 KB
/
EnumO.h
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <ostream>
#include "Enum.h"
#define MY_ENUM_OSTREAM_OVERLOAD(EnumName) \
namespace enum_wrapper_ { \
inline std::ostream &operator<<(std::ostream &os, EnumName##Impl value) { \
os << toPretty(value); \
return os; \
} \
} // namespace enum_wrapper_
// Convenience marco which defines the enum plus alias and adds the ostream
// overload.
#define MY_ENUM_O(EnumName, ...) \
MY_ENUM(EnumName, __VA_ARGS__); \
MY_ENUM_OSTREAM_OVERLOAD(EnumName)
// Convenience marco which defines the enum and adds the ostream overload.
#define MY_ENUM_DEF_O(EnumName, ...) \
MY_ENUM_DEF(EnumName, __VA_ARGS__); \
MY_ENUM_OSTREAM_OVERLOAD(EnumName)
// In Windows, MY_ENUM_O triggers harmless warning in boost macros
// BOOST_PP_SEQ_DETAIL_IS_NOT_EMPTY and BOOST_PP_SEQ_DETAIL_EMPTY_SIZE:
// "warning C4003: not enough arguments for function-like macro invocation".
// Frustratingly, disabling the warning directly in in MY_ENUM_O won't actually
// stop the compiler from reporting the warning; the caller needs to disable
// the warning seperately.
#if defined(_MSC_VER) && !defined(__clang__)
#define DISABLE_MY_ENUM_O_WARNINGS \
__pragma(warning(push)) __pragma(warning(disable : 4003))
#define ENABLE_MY_ENUM_O_WARNINGS __pragma(warning(pop))
#else
#define DISABLE_MY_ENUM_O_WARNINGS
#define ENABLE_MY_ENUM_O_WARNINGS
#endif