xref: /aosp_15_r20/external/google-fruit/include/fruit/impl/fruit-config.h (revision a65addddcf69f38db5b288d787b6b7571a57bb8f)
1*a65addddSAndroid Build Coastguard Worker /*
2*a65addddSAndroid Build Coastguard Worker  * Copyright 2014 Google Inc. All rights reserved.
3*a65addddSAndroid Build Coastguard Worker  *
4*a65addddSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*a65addddSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*a65addddSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*a65addddSAndroid Build Coastguard Worker  *
8*a65addddSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*a65addddSAndroid Build Coastguard Worker  *
10*a65addddSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*a65addddSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*a65addddSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*a65addddSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*a65addddSAndroid Build Coastguard Worker  * limitations under the License.
15*a65addddSAndroid Build Coastguard Worker  */
16*a65addddSAndroid Build Coastguard Worker 
17*a65addddSAndroid Build Coastguard Worker #ifndef FRUIT_CONFIG_H
18*a65addddSAndroid Build Coastguard Worker #define FRUIT_CONFIG_H
19*a65addddSAndroid Build Coastguard Worker 
20*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/fruit-config-base.h>
21*a65addddSAndroid Build Coastguard Worker 
22*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_STD_IS_TRIVIALLY_COPYABLE
23*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
24*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T)                                                                                 \
25*a65addddSAndroid Build Coastguard Worker   (std::is_trivially_copyable<T>::value || (std::is_empty<T>::value && std::is_trivially_copy_constructible<T>::value))
26*a65addddSAndroid Build Coastguard Worker #else // !FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
27*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T) (std::is_trivially_copyable<T>::value)
28*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
29*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_IS_TRIVIALLY_COPYABLE
30*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
31*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T)                                                                                 \
32*a65addddSAndroid Build Coastguard Worker   (__is_trivially_copyable(T) || (std::is_empty<T>::value && std::is_trivially_copy_constructible<T>::value))
33*a65addddSAndroid Build Coastguard Worker #else // !FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
34*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T) (__is_trivially_copyable(T))
35*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
36*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_HAS_TRIVIAL_COPY
37*a65addddSAndroid Build Coastguard Worker // The compiler doesn't support __is_trivially_copyable (nor is std::is_trivially_copyable
38*a65addddSAndroid Build Coastguard Worker // supported by the library). We use this check as a proxy, but it's not exactly the same thing.
39*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
40*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T)                                                                                 \
41*a65addddSAndroid Build Coastguard Worker   (__has_trivial_copy(T) || (std::is_empty<T>::value && std::is_trivially_copy_constructible<T>::value))
42*a65addddSAndroid Build Coastguard Worker #else // !FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
43*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T) (__has_trivial_copy(T))
44*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
45*a65addddSAndroid Build Coastguard Worker #else
46*a65addddSAndroid Build Coastguard Worker // We use the standard one, but most likely it won't work.
47*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
48*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T)                                                                                 \
49*a65addddSAndroid Build Coastguard Worker   (std::is_trivially_copyable<T>::value || (std::is_empty<T>::value && std::is_trivially_copy_constructible<T>::value))
50*a65addddSAndroid Build Coastguard Worker #else // !FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
51*a65addddSAndroid Build Coastguard Worker #define FRUIT_IS_TRIVIALLY_COPYABLE(T) (std::is_trivially_copyable<T>::value)
52*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_HAS_STD_IS_TRIVIALLY_COPY_CONSTRUCTIBLE
53*a65addddSAndroid Build Coastguard Worker #endif
54*a65addddSAndroid Build Coastguard Worker 
55*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_ALWAYS_INLINE_ATTRIBUTE
56*a65addddSAndroid Build Coastguard Worker #define FRUIT_ALWAYS_INLINE __attribute__((always_inline))
57*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_FORCEINLINE
58*a65addddSAndroid Build Coastguard Worker #define FRUIT_ALWAYS_INLINE __forceinline
59*a65addddSAndroid Build Coastguard Worker #else
60*a65addddSAndroid Build Coastguard Worker #define FRUIT_ALWAYS_INLINE
61*a65addddSAndroid Build Coastguard Worker #endif
62*a65addddSAndroid Build Coastguard Worker 
63*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_GCC_ATTRIBUTE_DEPRECATED
64*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DECLARATION(...) __VA_ARGS__ __attribute__((deprecated))
65*a65addddSAndroid Build Coastguard Worker // Marking the declaration is enough.
66*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DEFINITION(...) __VA_ARGS__
67*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_DECLSPEC_DEPRECATED
68*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DECLARATION(...) __declspec(deprecated) __VA_ARGS__
69*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DEFINITION(...) __declspec(deprecated) __VA_ARGS__
70*a65addddSAndroid Build Coastguard Worker // We use this only if the above two are not supported, because some compilers "support" this syntax (i.e., it compiles)
71*a65addddSAndroid Build Coastguard Worker // but they just ignore the attribute.
72*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_ATTRIBUTE_DEPRECATED
73*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DECLARATION(...) [[deprecated]] __VA_ARGS__
74*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DEFINITION(...) [[deprecated]] __VA_ARGS__
75*a65addddSAndroid Build Coastguard Worker #else
76*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DECLARATION(...) __VA_ARGS__
77*a65addddSAndroid Build Coastguard Worker #define FRUIT_DEPRECATED_DEFINITION(...) __VA_ARGS__
78*a65addddSAndroid Build Coastguard Worker #endif
79*a65addddSAndroid Build Coastguard Worker 
80*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_MSVC_ASSUME
81*a65addddSAndroid Build Coastguard Worker #define FRUIT_UNREACHABLE                                                                                              \
82*a65addddSAndroid Build Coastguard Worker   FruitAssert(false);                                                                                                  \
83*a65addddSAndroid Build Coastguard Worker   __assume(0)
84*a65addddSAndroid Build Coastguard Worker #elif FRUIT_HAS_BUILTIN_UNREACHABLE
85*a65addddSAndroid Build Coastguard Worker #define FRUIT_UNREACHABLE                                                                                              \
86*a65addddSAndroid Build Coastguard Worker   FruitAssert(false);                                                                                                  \
87*a65addddSAndroid Build Coastguard Worker   __builtin_unreachable()
88*a65addddSAndroid Build Coastguard Worker #endif
89*a65addddSAndroid Build Coastguard Worker 
90*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_CONFIG_H
91