Add default initialization to compressed_pair.
This change introduces the __default_init_tag to memory, and a corresponding
element constructor to allow for default initialization of either of the pair
values. This is useful for classes such as std::string where most (all)
constructors explicitly initialize the values in the constructor.
Patch by Martijn Vels (mvels@google.com)
Reviewed as https://reviews.llvm.org/D70617
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 0fa118a9da6786a0aaf81e309d8c3b38bc5f61dd
diff --git a/include/memory b/include/memory
index 1723b30..45e032a 100644
--- a/include/memory
+++ b/include/memory
@@ -2178,6 +2178,9 @@
};
#endif
+// Tag used to default initialize one or both of the pair's elements.
+struct __default_init_tag {};
+
template <class _Tp, int _Idx,
bool _CanBeEmptyBase =
is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
@@ -2188,6 +2191,8 @@
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
+ _LIBCPP_INLINE_VISIBILITY constexpr
+ __compressed_pair_elem(__default_init_tag) {}
template <class _Up, class = typename enable_if<
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
@@ -2207,6 +2212,8 @@
#else
_LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
_LIBCPP_INLINE_VISIBILITY
+ __compressed_pair_elem(__default_init_tag) {}
+ _LIBCPP_INLINE_VISIBILITY
__compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
#endif