std::reference_wrapper for builtin and user types
()
| 447 | |
| 448 | |
| 449 | def test_reference_wrapper(): |
| 450 | """std::reference_wrapper for builtin and user types""" |
| 451 | assert m.refwrap_builtin(42) == 420 |
| 452 | assert m.refwrap_usertype(UserType(42)) == 42 |
| 453 | assert m.refwrap_usertype_const(UserType(42)) == 42 |
| 454 | |
| 455 | with pytest.raises(TypeError) as excinfo: |
| 456 | m.refwrap_builtin(None) |
| 457 | assert "incompatible function arguments" in str(excinfo.value) |
| 458 | |
| 459 | with pytest.raises(TypeError) as excinfo: |
| 460 | m.refwrap_usertype(None) |
| 461 | assert "incompatible function arguments" in str(excinfo.value) |
| 462 | |
| 463 | assert m.refwrap_lvalue().value == 1 |
| 464 | assert m.refwrap_lvalue_const().value == 1 |
| 465 | |
| 466 | a1 = m.refwrap_list(copy=True) |
| 467 | a2 = m.refwrap_list(copy=True) |
| 468 | assert [x.value for x in a1] == [2, 3] |
| 469 | assert [x.value for x in a2] == [2, 3] |
| 470 | assert a1[0] is not a2[0] |
| 471 | assert a1[1] is not a2[1] |
| 472 | |
| 473 | b1 = m.refwrap_list(copy=False) |
| 474 | b2 = m.refwrap_list(copy=False) |
| 475 | assert [x.value for x in b1] == [1, 2] |
| 476 | assert [x.value for x in b2] == [1, 2] |
| 477 | assert b1[0] is b2[0] |
| 478 | assert b1[1] is b2[1] |
| 479 | |
| 480 | assert m.refwrap_iiw(IncType(5)) == 5 |
| 481 | assert m.refwrap_call_iiw(IncType(10), m.refwrap_iiw) == [10, 10, 10, 10] |
| 482 | |
| 483 | |
| 484 | def test_complex_cast(doc): |