Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"auto&&" preceded by concept "con" is not a "universal reference as shown below. Remove the constraint by changing "con auto&&" to "auto&&" and it is a "universal reference" (no compilation error). Could someone please explain why?
C++
#include<concepts>
class Base { public: Base() {} };
class Derived : public Base { public: Derived() {} };
template<typename t>
concept con = std::is_class_v<t> && std::derived_from<t, base>;

void f(con auto&& x) {}

int main()
{
	f(Derived()); // r-value: Ok
	Derived d;
	f(d); // l-value: MSVC ERROR "no matching overloaded function found"
}


What I have tried:

Internet search for the specific case described here.
Posted
Updated 18-Jan-24 18:00pm
v3

 
Share this answer
 
In your code:
template<typename t>
concept con = std::is_class_v<t> && std::derived_from<t, base>;

I guess should be Base instead of base
 
Share this answer
 
Comments
Member 14620282 19-Jan-24 19:46pm    
It is Base (capitalized) in the code. Apparently that is some sort of cut/paste issue...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900