-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Adjusting type_caster<std::reference_wrapper<T>> to support const/non-const propagation in cast_op.
#2705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjusting type_caster<std::reference_wrapper<T>> to support const/non-const propagation in cast_op.
#2705
Changes from 24 commits
65abb62
c603907
5cdc0ca
35e7fa5
4cd06d3
5abd823
c5bd104
f0e41f5
b56a568
d71cd7a
3c69635
8f32ba3
d144e59
a7ec72e
e1aca4b
005d3fe
4ac23ca
a3d9b18
5b4fb98
8dcbc42
9f77862
7672e92
c747ae2
33f57cc
d869976
f109edd
775a7c9
6f6dac7
fd6dc5b
b3ecc53
c22772b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -960,9 +960,15 @@ template <typename type> class type_caster<std::reference_wrapper<type>> { | |||||||||||||||||||
| private: | ||||||||||||||||||||
| using caster_t = make_caster<type>; | ||||||||||||||||||||
| caster_t subcaster; | ||||||||||||||||||||
| using subcaster_cast_op_type = typename caster_t::template cast_op_type<type>; | ||||||||||||||||||||
| static_assert(std::is_same<typename std::remove_const<type>::type &, subcaster_cast_op_type>::value, | ||||||||||||||||||||
| "std::reference_wrapper<T> caster requires T to have a caster with an `T &` operator"); | ||||||||||||||||||||
| using reference_t = typename std::add_lvalue_reference<type>::type; | ||||||||||||||||||||
|
||||||||||||||||||||
| using subcaster_cast_op_type = | ||||||||||||||||||||
laramiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| typename caster_t::template cast_op_type<reference_t>; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| static_assert((std::is_same<typename std::remove_const<type>::type &, | ||||||||||||||||||||
| subcaster_cast_op_type>::value || | ||||||||||||||||||||
| std::is_same<reference_t, subcaster_cast_op_type>::value), | ||||||||||||||||||||
| "std::reference_wrapper<T> caster requires T to have a caster " | ||||||||||||||||||||
| "with an operator `T &` or `const T&`"); | ||||||||||||||||||||
|
||||||||||||||||||||
| static_assert((std::is_same<typename std::remove_const<type>::type &, | |
| subcaster_cast_op_type>::value || | |
| std::is_same<reference_t, subcaster_cast_op_type>::value), | |
| "std::reference_wrapper<T> caster requires T to have a caster " | |
| "with an operator `T &` or `const T&`"); | |
| static_assert(std::is_same<typename std::remove_const<type>::type &, subcaster_cast_op_type>::value || | |
| std::is_same<reference_t, subcaster_cast_op_type>::value, | |
| "std::reference_wrapper<T> caster requires T to have a caster with an " | |
| "`operator T &()` or `operator const T &()`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| operator std::reference_wrapper<type>() { return subcaster.operator subcaster_cast_op_type(); } | |
| operator std::reference_wrapper<type>() { return cast_op<reference_t>(subcaster); } |
or even (depending on the other discussion)
| operator std::reference_wrapper<type>() { return subcaster.operator subcaster_cast_op_type(); } | |
| operator std::reference_wrapper<type>() { return cast_op<type &>(subcaster); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you already listed point 3/ where I removed a & based on review feedback as a "separate change"; how is this not the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? I don't mean this should be taken out, but if you go and change std::add_lvalue_reference<type> to type &, this part can also be simplified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't agree with the suggestion in #2705 (comment), that's also fine with me; then just argue why not and do not do it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean operator std::reference_wrapper<type>() { return cast_op<type &>(subcaster); } is clearly a more substantive change than removing & from operator std::reference_wrapper<type>() { return subcaster.operator subcaster_cast_op_type(); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, yes. I just saw this being used in other casters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also fine with not applying this change; it's supposed to do exactly the same, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Uh oh!
There was an error while loading. Please reload this page.