libcopp  1.2.0
explicit_declare.h
Go to the documentation of this file.
1 
13 #ifndef STD_EXPLICIT_DECLARE_H
14 #define STD_EXPLICIT_DECLARE_H
15 
16 
17 #pragma once
18 
19 // ============================================================
20 // 公共包含部分
21 // C++0x/11/14/17 显示申明
22 // ============================================================
23 
24 #ifndef PARAM_IN
25 #if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
26 #define PARAM_IN _In_
27 #else
28 #define PARAM_IN
29 #endif
30 #endif
31 
32 #ifndef PARAM_OUT
33 #if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
34 #define PARAM_OUT _Out_
35 #else
36 #define PARAM_OUT
37 #endif
38 #endif
39 
40 #ifndef PARAM_INOUT
41 #if defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
42 #define PARAM_INOUT _Inout_
43 #else
44 #define PARAM_INOUT
45 #endif
46 #endif
47 
48 
60 #if defined(__cplusplus) && __cplusplus >= 201402L
61 #define EXPLICIT_DEPRECATED_ATTR [[deprecated]]
62 #elif defined(__clang__)
63 #define EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
64 #elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
65 #define EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
66 #elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
67 #if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
68 #define EXPLICIT_DEPRECATED_ATTR [[deprecated]]
69 #else
70 #define EXPLICIT_DEPRECATED_ATTR __declspec(deprecated)
71 #endif
72 #else
73 #define EXPLICIT_DEPRECATED_ATTR
74 #endif
75 
76 #if defined(__cplusplus) && __cplusplus >= 201402L
77 #define EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
78 #elif defined(__clang__)
79 #define EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
80 #elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
81 #define EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
82 #elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
83 #if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
84 #define EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
85 #else
86 #define EXPLICIT_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
87 #endif
88 #else
89 #define EXPLICIT_DEPRECATED_MSG(msg)
90 #endif
91 
99 #if defined(__cplusplus) && __cplusplus >= 201703L
100 #define EXPLICIT_NODISCARD_ATTR [[nodiscard]]
101 #elif defined(__clang__)
102 #define EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
103 #elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
104 #define EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
105 #elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
106 #if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
107 #define EXPLICIT_NODISCARD_ATTR [[nodiscard]]
108 #else
109 #define EXPLICIT_NODISCARD_ATTR _Check_return_
110 #endif
111 #else
112 #define EXPLICIT_NODISCARD_ATTR
113 #endif
114 
122 #if defined(__cplusplus) && __cplusplus >= 201703L
123 #define EXPLICIT_UNUSED_ATTR [[maybe_unused]]
124 #elif defined(__clang__)
125 #define EXPLICIT_UNUSED_ATTR __attribute__((unused))
126 #elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
127 #define EXPLICIT_UNUSED_ATTR __attribute__((unused))
128 #elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
129 #if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
130 #define EXPLICIT_UNUSED_ATTR [[maybe_unused]]
131 #else
132 #define EXPLICIT_UNUSED_ATTR
133 #endif
134 #else
135 #define EXPLICIT_UNUSED_ATTR
136 #endif
137 
146 #if defined(__cplusplus) && __cplusplus >= 201703L
147 #define EXPLICIT_FALLTHROUGH [[fallthrough]];
148 #elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__) >= 309
149 #if defined(__apple_build_version__)
150 #define EXPLICIT_FALLTHROUGH
151 #elif defined(__has_warning) && __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
152 #define EXPLICIT_FALLTHROUGH [[clang::fallthrough]];
153 #else
154 #define EXPLICIT_FALLTHROUGH
155 #endif
156 #elif defined(__GNUC__) && (__GNUC__ >= 7)
157 #define EXPLICIT_FALLTHROUGH [[gnu::fallthrough]];
158 #elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
159 #if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
160 #define EXPLICIT_FALLTHROUGH [[fallthrough]];
161 #else
162 #define EXPLICIT_FALLTHROUGH
163 #endif
164 #else
165 #define EXPLICIT_FALLTHROUGH
166 #endif
167 
168 #endif