diff options
Diffstat (limited to 'absl/base/optimization.h')
-rw-r--r-- | absl/base/optimization.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/absl/base/optimization.h b/absl/base/optimization.h index db5cc097..57999a18 100644 --- a/absl/base/optimization.h +++ b/absl/base/optimization.h @@ -249,4 +249,28 @@ #define ABSL_INTERNAL_UNIQUE_SMALL_NAME() #endif +// ABSL_IS_TRIVIALLY_RELOCATABLE(type) +// Detects whether a type is "trivially relocatable" -- meaning it can be +// relocated without invoking the constructor/destructor, using a form of move +// elision. +// +// Example: +// +// if constexpr (ABSL_IS_TRIVIALLY_RELOCATABLE(T)) { +// memcpy(new_location, old_location, sizeof(T)); +// } else { +// new(new_location) T(std::move(*old_location)); +// old_location->~T(); +// } +// +// Upstream documentation: +// +// https://clang.llvm.org/docs/LanguageExtensions.html#:~:text=__is_trivially_relocatable +// +#if ABSL_HAVE_BUILTIN(__is_trivially_relocatable) +#define ABSL_IS_TRIVIALLY_RELOCATABLE(type) __is_trivially_relocatable(type) +#else +#define ABSL_IS_TRIVIALLY_RELOCATABLE(type) false +#endif + #endif // ABSL_BASE_OPTIMIZATION_H_ |