xref: /aosp_15_r20/external/pigweed/pw_polyfill/public/pw_polyfill/standard.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #if defined(__cplusplus)
17 
18 /// Evaluates true if the provided C++ standard (98, 11, 14, 17, 20, 23) is
19 /// supported by the compiler. This is a simple alternative to checking the
20 /// value of the `__cplusplus` macro.
21 #define PW_CXX_STANDARD_IS_SUPPORTED(std) \
22   (__cplusplus >= _PW_CXX_STANDARD_##std())
23 
24 /// Evaluates true if the provided C standard (89, 98, 11, 17, 23) is supported
25 /// by the compiler. This is a simple alternative to checking the value of the
26 /// `__STDC_VERSION__` macro.
27 #define PW_C_STANDARD_IS_SUPPORTED(std) (0 >= _PW_C_STANDARD_##std())
28 
29 #elif defined(__STDC_VERSION__)
30 
31 #define PW_CXX_STANDARD_IS_SUPPORTED(std) (0 >= _PW_CXX_STANDARD_##std())
32 
33 #define PW_C_STANDARD_IS_SUPPORTED(std) \
34   (__STDC_VERSION__ >= _PW_C_STANDARD_##std())
35 
36 #endif  // defined(__cplusplus)
37 
38 // Standard values of __cplusplus and __STDC_VERSION__. See the GCC docs for
39 // more info: https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
40 #define _PW_CXX_STANDARD_98() 199711L
41 #define _PW_CXX_STANDARD_11() 201103L
42 #define _PW_CXX_STANDARD_14() 201402L
43 #define _PW_CXX_STANDARD_17() 201703L
44 #define _PW_CXX_STANDARD_20() 202002L
45 #define _PW_CXX_STANDARD_23() 202302L
46 
47 #define _PW_C_STANDARD_89() 199409L
48 #define _PW_C_STANDARD_99() 199901L
49 #define _PW_C_STANDARD_11() 201112L
50 #define _PW_C_STANDARD_17() 201710L
51 #define _PW_C_STANDARD_23() 202311L
52