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