test pair-copyability on C++17 upwards (#1886)
* test pair-copyability on C++17 upwards
The stdlib falsely detects containers like M=std::map<T, U>
as copyable, even when one of T and U is not copyable.
Therefore we cannot rely on the stdlib dismissing std::pair<T, M>
by itself, even on C++17.
* 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.
* created tests for copyability
diff --git a/tests/test_stl_binders.py b/tests/test_stl_binders.py
index 6d5a159..b83a587 100644
--- a/tests/test_stl_binders.py
+++ b/tests/test_stl_binders.py
@@ -212,6 +212,44 @@
assert vsum == 150
+ # nested std::map<std::vector>
+ nvnc = m.get_nvnc(5)
+ for i in range(1, 6):
+ for j in range(0, 5):
+ assert nvnc[i][j].value == j + 1
+
+ for k, v in nvnc.items():
+ for i, j in enumerate(v, start=1):
+ assert j.value == i
+
+ # nested std::map<std::map>
+ nmnc = m.get_nmnc(5)
+ for i in range(1, 6):
+ for j in range(10, 60, 10):
+ assert nmnc[i][j].value == 10 * j
+
+ vsum = 0
+ for k_o, v_o in nmnc.items():
+ for k_i, v_i in v_o.items():
+ assert v_i.value == 10 * k_i
+ vsum += v_i.value
+
+ assert vsum == 7500
+
+ # nested std::unordered_map<std::unordered_map>
+ numnc = m.get_numnc(5)
+ for i in range(1, 6):
+ for j in range(10, 60, 10):
+ assert numnc[i][j].value == 10 * j
+
+ vsum = 0
+ for k_o, v_o in numnc.items():
+ for k_i, v_i in v_o.items():
+ assert v_i.value == 10 * k_i
+ vsum += v_i.value
+
+ assert vsum == 7500
+
def test_map_delitem():
mm = m.MapStringDouble()