r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jun 04 '26
Do concepts improve deducing this?
https://meetingcpp.com/blog/items/Do-concepts-improve-deducing-this-.html
26
Upvotes
r/cpp • u/meetingcpp Meeting C++ | C++ Evangelist • Jun 04 '26
View all comments
12
u/__christo4us Jun 04 '26
You do not need to fallback to ref-qualifiers to do this. You can still provide an overload with an explicit object parameter:
The above will not work as intended because a concept is always applied solely to
auto(excluding the&&) and ifsetLogLevelis invoked with an rvalue argument, theautois always deduced to a non-referenced type. It is never deduced to an rvalue reference, neither for prvalue nor xvalue arguments. It is however deduced to an lvalue reference type if an lvalue is used as the argument. This is how forwarding references work in general. You could change the concept definition as follows: