Skip to content

Commit 46d0c5e

Browse files
committed
fix is_copy_assignable
bind_map used std::is_copy_assignable which suffers from the same problems as std::is_copy_constructible, therefore the same fix has been applied.
1 parent 1ae7d52 commit 46d0c5e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/pybind11/cast.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,15 @@ template <typename Container> struct is_copy_constructible<Container, enable_if_
803803
template <typename T1, typename T2> struct is_copy_constructible<std::pair<T1, T2>>
804804
: all_of<is_copy_constructible<T1>, is_copy_constructible<T2>> {};
805805

806+
// The same problems arise with std::is_copy_assignable, so we use the same workaround.
807+
template <typename T, typename SFINAE = void> struct is_copy_assignable : std::is_copy_assignable<T> {};
808+
template <typename Container> struct is_copy_assignable<Container, enable_if_t<all_of<
809+
std::is_copy_assignable<Container>,
810+
std::is_same<typename Container::value_type &, typename Container::reference>
811+
>::value>> : is_copy_assignable<typename Container::value_type> {};
812+
template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>>
813+
: all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {};
814+
806815
NAMESPACE_END(detail)
807816

808817
// polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed

include/pybind11/stl_bind.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ template <typename, typename, typename... Args> void map_assignment(const Args &
512512

513513
// Map assignment when copy-assignable: just copy the value
514514
template <typename Map, typename Class_>
515-
void map_assignment(enable_if_t<std::is_copy_assignable<typename Map::mapped_type>::value, Class_> &cl) {
515+
void map_assignment(enable_if_t<is_copy_assignable<typename Map::mapped_type>::value, Class_> &cl) {
516516
using KeyType = typename Map::key_type;
517517
using MappedType = typename Map::mapped_type;
518518

@@ -528,7 +528,7 @@ void map_assignment(enable_if_t<std::is_copy_assignable<typename Map::mapped_typ
528528
// Not copy-assignable, but still copy-constructible: we can update the value by erasing and reinserting
529529
template<typename Map, typename Class_>
530530
void map_assignment(enable_if_t<
531-
!std::is_copy_assignable<typename Map::mapped_type>::value &&
531+
!is_copy_assignable<typename Map::mapped_type>::value &&
532532
is_copy_constructible<typename Map::mapped_type>::value,
533533
Class_> &cl) {
534534
using KeyType = typename Map::key_type;

0 commit comments

Comments
 (0)