Pigweed
C/C++ API Reference
Home
Modules
Loading...
Searching...
No Matches
language_feature_macros.h
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
15
// Macros for using C++ features in older standards.
16
#pragma once
17
19
26
#if __cplusplus >= 202002L
27
#define PW_CONSTEXPR_CPP20 constexpr
28
#else
29
#define PW_CONSTEXPR_CPP20
30
#endif
// __cpp_constexpr >= 201304L
31
37
#if defined(__cpp_consteval) && __cpp_consteval >= 201811L
38
#define PW_CONSTEVAL consteval
39
#else
40
#define PW_CONSTEVAL constexpr
41
#endif
// __cpp_consteval >= 201811L
42
45
#if defined(__cpp_constinit) && __cpp_constinit >= 201907L
46
#define PW_CONSTINIT constinit
47
#elif defined(__clang__)
48
#define PW_CONSTINIT [[clang::require_constant_initialization]]
49
#elif defined(__GNUC__) && __GNUC__ >= 10
50
#define PW_CONSTINIT __constinit
51
#else
52
#define PW_CONSTINIT \
53
static_assert(false, \
54
"PW_CONSTINIT does not yet support this compiler; "
\
55
"implement PW_CONSTINIT for this compiler to use it.");
56
#endif
// __cpp_constinit
57
60
#if __cplusplus >= 202002L
61
#define PW_NODISCARD_STR(str) [[nodiscard(str)]]
62
#else
63
#define PW_NODISCARD_STR(str) [[nodiscard]]
64
#endif
// __cplusplus >= 202002L
pw_polyfill
public
pw_polyfill
language_feature_macros.h
Generated by
1.9.6