Skip to content

Commit c4a3034

Browse files
Fix for move_assign
1 parent 8da6b53 commit c4a3034

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

libcxx/include/__tree

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,11 +1053,11 @@ public:
10531053
#if _LIBCPP_STD_VER >= 26
10541054
if (__libcpp_is_constant_evaluated()) {
10551055
// static_assert(std::same_as_v<decltype(__value.first), double>);
1056-
// __emplace_hint_unique(__p, std::move(__value.first), std::move(__value.second));
1056+
__emplace_hint_unique(__p, std::move(__value.first), std::move(__value.second));
10571057

1058-
__sfinae_call_emplace_hint_unique(__p, std::move(__value),
1059-
integral_constant<bool, is_copy_constructible<decltype(__value.first)>::value >()
1060-
);
1058+
// __sfinae_call_emplace_hint_unique(__p, std::move(__value),
1059+
// integral_constant<bool, is_copy_constructible<decltype(__value.first)>::value >()
1060+
// );
10611061
} else
10621062
#endif
10631063
{
@@ -1239,30 +1239,66 @@ private:
12391239

12401240

12411241
// todo; mark consteval?
1242-
#ifdef FAKE_VINAY
1242+
// #ifdef FAKE_VINAY
12431243

12441244
template <class _From, class _ValueT = _Tp,
12451245
__enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0
1246-
, __enable_if_t< ! is_copy_constructible_v< typename _From::first_type >, int> = 0
1246+
1247+
// , typename = std::enable_if_t<
1248+
// !std::is_copy_constructible_v<
1249+
// std::remove_cvref_t<decltype(std::declval<_From>().first)>
1250+
// >
1251+
// >
12471252
>
1253+
requires (!std::is_copy_constructible_v<
1254+
std::remove_cvref_t<decltype(std::declval<_From>().first)>
1255+
>)
12481256
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_from_value_type(
12491257
__get_node_value_type_t<value_type>& __lhs, _From&& __rhs/*, false_type*/) _NOEXCEPT {
12501258
(void)__lhs;
12511259
(void)__rhs;
1252-
static_assert(false, "Can not move from a pair<const T, T>");
1260+
// static_assert(false, "Can not move from a pair<const T, U>");
1261+
// TODO: how do I flag this code to NOT run at compile time?
1262+
// Using static_assert means this can't compile _at all_, regardless of whether this code is actually going to execute at compile time or not
12531263
}
12541264

12551265
template <class _From, class _ValueT = _Tp,
12561266
__enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0
12571267

12581268
// Check if first type can be copy constructed
1259-
, __enable_if_t< is_copy_constructible_v< typename _From::first_type >, int> = 0
1269+
1270+
// , typename = std::enable_if_t<
1271+
// std::is_copy_constructible_v<
1272+
// std::remove_cvref_t<decltype(std::declval<_From>().first)>
1273+
// >
1274+
// >
12601275
>
1276+
requires ( std::is_copy_constructible_v<
1277+
std::remove_cvref_t<decltype(std::declval<_From>().first)>
1278+
>)
12611279
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __move_from_value_type(
12621280
__get_node_value_type_t<value_type>& __lhs, _From&& __rhs/*, true_type*/) _NOEXCEPT {
12631281

1282+
1283+
// const_cast is not allowed at constexpr time.
1284+
// we get around this by deleting __lhs and creating a new node in-place
1285+
// to avoid const_cast -ing __lhs.first
1286+
1287+
// note: this does not work for `const MoveOnly` keys at constexpr time
1288+
1289+
1290+
__node_allocator& __na = __node_alloc();
1291+
__node_traits::destroy(__na, std::addressof(__lhs));
1292+
1293+
// __get_node_value_type_t<value_type> __tmp(__rhs);
1294+
using __node_value_type = __get_node_value_type_t<value_type>;
1295+
__get_node_value_type_t<value_type> __tmp(__rhs.first, __rhs.second);
1296+
__node_traits::construct(__na, std::addressof(__lhs), std::move(__tmp));
1297+
1298+
1299+
12641300
}
1265-
#endif
1301+
// #endif
12661302

12671303

12681304

@@ -1280,25 +1316,9 @@ error: no matching constructor for initialization of '__get_node_value_type_t<va
12801316
# | 1225 | __get_node_value_type_t<value_type> __tmp(__rhs.first, __rhs.second);
12811317
*/
12821318
if (__libcpp_is_constant_evaluated()) {
1283-
// __move_from_value_type(__lhs, __rhs
1319+
__move_from_value_type(__lhs, __rhs
12841320
// , integral_constant<bool, is_copy_constructible_v<_From> >()
1285-
// );
1286-
1287-
using __node_value_type = __get_node_value_type_t<value_type>;
1288-
__get_node_value_type_t<value_type> __tmp(__rhs.first, __rhs.second);
1289-
// __get_node_value_type_t<value_type> __tmp(__rhs);
1290-
1291-
// const_cast is not allowed at constexpr time.
1292-
// we get around this by deleting __lhs and creating a new node in-place
1293-
// to avoid const_cast -ing __lhs.first
1294-
1295-
// note: this does not work for `const MoveOnly` keys at constexpr time
1296-
1297-
// __lhs.~__node_value_type();
1298-
__node_allocator& __na = __node_alloc();
1299-
__node_traits::destroy(__na, std::addressof(__lhs));
1300-
__node_traits::construct(__na, std::addressof(__lhs), std::move(__tmp));
1301-
1321+
);
13021322

13031323

13041324

0 commit comments

Comments
 (0)