Click here to Skip to main content
15,123,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to write a concept which requires a class type have a particular templated method as below?
struct struct_a
{
	template<typename T> void foobar(T&) {}
}

template<typename T> requires templated_foobar<T> // how to write this concept?
struct struct_b { }

int main()
{
	struct_b<struct_a> b;
}


What I have tried:

template<typename T>
concept templated_foobar = requires (T t) { t.foobar(); }; // requirement not met
template<typename T>
concept templated_foobar = requires (T t) { template<typename U> t.foobar(U); }; // syntax error
Posted
Updated 5-Jul-21 4:28am

The page mentioned above links to this[^], which covers the details. Sorry I can't help beyond that, because I don't use constraints.
   

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