Skip to content

Commit 86299e3

Browse files
committed
uncommenting & adjusting additional test; adding back original code with #if #else #endif
1 parent b34d56f commit 86299e3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/pybind11/cast.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,11 @@ template <typename type> class type_caster<std::reference_wrapper<type>> {
960960
private:
961961
using caster_t = make_caster<type>;
962962
caster_t subcaster;
963+
#if 1
964+
using subcaster_cast_op_type = typename caster_t::template cast_op_type<type>;
965+
static_assert(std::is_same<typename std::remove_const<type>::type &, subcaster_cast_op_type>::value,
966+
"std::reference_wrapper<T> caster requires T to have a caster with an `T &` operator");
967+
#else
963968
using reference_t = typename std::add_lvalue_reference<type>::type;
964969
using subcaster_cast_op_type =
965970
typename caster_t::template cast_op_type<reference_t>;
@@ -969,6 +974,7 @@ template <typename type> class type_caster<std::reference_wrapper<type>> {
969974
std::is_same<reference_t, subcaster_cast_op_type>::value),
970975
"std::reference_wrapper<T> caster requires T to have a caster "
971976
"with an `T &` operator or `const T&` operator");
977+
#endif
972978
public:
973979
bool load(handle src, bool convert) { return subcaster.load(src, convert); }
974980
static constexpr auto name = caster_t::name;

tests/test_builtin_casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ def test_reference_wrapper():
327327

328328
assert m.refwrap_lvalue_const().value == 1
329329
# const-ness is not propagated.
330-
# m.refwrap_lvalue_const().value =2
331-
# assert m.refwrap_lvalue_const().value == 1
330+
m.refwrap_lvalue_const().value = 2
331+
assert m.refwrap_lvalue_const().value == 2
332332

333333
assert m.refwrap_lvalue().value == 1
334334
m.refwrap_lvalue().value = 4

0 commit comments

Comments
 (0)