From a02f62f456f2c4a7ecf2be3104fe0c6e16fbad9a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 12 Apr 2019 00:26:40 -0700 Subject: Export of internal Abseil changes. -- 5755b40f6025f3ca126070fc68adb8fde9a7f01b by Abseil Team : Fix -Wextra-semi error. PiperOrigin-RevId: 243215850 -- 3b6b6e18df9fbd233943cae460f0063f4efaa7c7 by Eric Fiselier : Internal Change. PiperOrigin-RevId: 243152671 -- 82eef03f246009c806c25607c5682547cb4ad21e by Abseil Team : Internal change. PiperOrigin-RevId: 243151861 -- c14e6340fca7070634e0ecfdf97833d930dd0e5d by Samuel Benzaquen : Internal change PiperOrigin-RevId: 243123590 -- 9abb7a6b22457c0aa72d72b3b9392efd226d302a by Andy Getzendanner : Implement operator<<(std::ostream &, absl::LogSeverity) so that absl::LogSeverity values can be streamed. PiperOrigin-RevId: 243117646 GitOrigin-RevId: 5755b40f6025f3ca126070fc68adb8fde9a7f01b Change-Id: I7ea607d8a4e803ad15a3090139271f58ad4173a3 --- absl/meta/type_traits.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'absl/meta/type_traits.h') diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index fbdc921..a8068e3 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -341,6 +341,49 @@ struct is_trivially_copy_assignable #endif // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE }; +namespace type_traits_internal { +// is_trivially_copyable() +// +// Determines whether the passed type `T` is trivially copyable. +// +// This metafunction is designed to be a drop-in replacement for the C++11 +// `std::is_trivially_copyable()` metafunction for platforms that have +// incomplete C++11 support (such as libstdc++ 4.x). We use the C++17 definition +// of TriviallyCopyable. +// +// NOTE: `is_trivially_copyable::value` is `true` if all of T's copy/move +// constructors/assignment operators are trivial or deleted, T has at least +// one non-deleted copy/move constructor/assignment operator, and T is trivially +// destructible. Arrays of trivially copyable types are trivially copyable. +// +// We expose this metafunction only for internal use within absl. +template +class is_trivially_copyable_impl { + using ExtentsRemoved = typename std::remove_all_extents::type; + static constexpr bool kIsCopyOrMoveConstructible = + std::is_copy_constructible::value || + std::is_move_constructible::value; + static constexpr bool kIsCopyOrMoveAssignable = + absl::is_copy_assignable::value || + absl::is_move_assignable::value; + + public: + static constexpr bool kValue = + (__has_trivial_copy(ExtentsRemoved) || !kIsCopyOrMoveConstructible) && + (__has_trivial_assign(ExtentsRemoved) || !kIsCopyOrMoveAssignable) && + (kIsCopyOrMoveConstructible || kIsCopyOrMoveAssignable) && + is_trivially_destructible::value && + // We need to check for this explicitly because otherwise we'll say + // references are trivial copyable when compiled by MSVC. + !std::is_reference::value; +}; + +template +struct is_trivially_copyable + : std::integral_constant< + bool, type_traits_internal::is_trivially_copyable_impl::kValue> {}; +} // namespace type_traits_internal + // ----------------------------------------------------------------------------- // C++14 "_t" trait aliases // ----------------------------------------------------------------------------- -- cgit v1.2.3