Skip to content

Commit c28aac0

Browse files
Allow runtime decision for __insert_unique_from_orphaned_node
1 parent 2661937 commit c28aac0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

libcxx/include/__tree

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,35 @@ public:
10541054
std::forward<_Args>(__args)...);
10551055
}
10561056

1057+
1058+
template <class... _Args>
1059+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
1060+
__emplace_hint_unique__sfinae(true_type, const_iterator __p, _Args&&... __args) {
1061+
return __emplace_hint_unique(__p, __args...);
1062+
}
1063+
1064+
template <class... _Args>
1065+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 pair<iterator, bool>
1066+
__emplace_hint_unique__sfinae(false_type, const_iterator , _Args&&... ) {
1067+
// This method body should never be run. It only exists to allow for compilation. See note in __insert_unique_from_orphaned_node for more information.
1068+
return pair<iterator, bool>(iterator(__node_pointer()), false);
1069+
}
1070+
10571071
template <class _ValueT = _Tp, __enable_if_t<__is_tree_value_type_v<_ValueT>, int> = 0>
10581072
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void
10591073
__insert_unique_from_orphaned_node(const_iterator __p, __get_node_value_type_t<_Tp>&& __value) {
10601074
#if _LIBCPP_STD_VER >= 26
1061-
if constexpr (std::is_copy_constructible_v<decltype(__value.first)>) {
1062-
__emplace_hint_unique(__p, std::move(__value.first), std::move(__value.second));
1075+
if (std::is_constant_evaluated() && std::is_copy_constructible_v<decltype(__value.first)>) {
1076+
1077+
// We create a sfinae wrapper method here, because if the __emplace_hint_unique method gets template instantiated within __insert_unique_from_orphaned_node, the code will fail to compile where the value is not copy_constructible for runtime execution as well; unless we use `if constexpr`.
1078+
// Given the copy-constructible code path will be a performance regression, we want to restrict it to only execute during constant evaluation
1079+
//, we need to delay the template instantiation
1080+
__emplace_hint_unique__sfinae(
1081+
integral_constant <
1082+
bool,
1083+
std::is_copy_constructible_v<decltype(__value.first)>
1084+
>(),
1085+
__p, std::move(__value.first), std::move(__value.second));
10631086
} else
10641087
#endif
10651088
{

0 commit comments

Comments
 (0)