1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_RELOCATABLE_H 10 #define _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_RELOCATABLE_H 11 12 #include <__config> 13 #include <__type_traits/enable_if.h> 14 #include <__type_traits/is_same.h> 15 #include <__type_traits/is_trivially_copyable.h> 16 17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 18 # pragma GCC system_header 19 #endif 20 21 _LIBCPP_BEGIN_NAMESPACE_STD 22 23 // A type is trivially relocatable if a move construct + destroy of the original object is equivalent to 24 // `memcpy(dst, src, sizeof(T))`. 25 // 26 // Note that we don't use the __is_trivially_relocatable Clang builtin right now because it does not 27 // implement the semantics of any current or future trivial relocation proposal and it can lead to 28 // incorrect optimizations on some platforms (Windows) and supported compilers (AppleClang). 29 #if __has_builtin(__is_trivially_relocatable) && 0 30 template <class _Tp, class = void> 31 struct __libcpp_is_trivially_relocatable : integral_constant<bool, __is_trivially_relocatable(_Tp)> {}; 32 #else 33 template <class _Tp, class = void> 34 struct __libcpp_is_trivially_relocatable : is_trivially_copyable<_Tp> {}; 35 #endif 36 37 template <class _Tp> 38 struct __libcpp_is_trivially_relocatable<_Tp, 39 __enable_if_t<is_same<_Tp, typename _Tp::__trivially_relocatable>::value> > 40 : true_type {}; 41 42 _LIBCPP_END_NAMESPACE_STD 43 44 #endif // _LIBCPP___TYPE_TRAITS_IS_TRIVIALLY_RELOCATABLE_H 45