How to implement overloading functions using boost concepts?
Hi, I would like to have overloading functions such that they are dispatched with boost concepts. See minimal example below: #include <iostream> #include <boost/concept/usage.hpp> #include <boost/concept/requires.hpp> template<class T> struct XConcept { BOOST_CONCEPT_USAGE(XConcept) { int x = t.x; } private: T t; }; template<class T> struct XYConcept : XConcept<T> { BOOST_CONCEPT_USAGE(XYConcept) { int y = t.y; } private: T t; }; template<typename T> BOOST_CONCEPT_REQUIRES( ((XConcept<T>)), (void)) foo(T t) { std::cout << "XConcept works!" << std::endl; } template<typename T> BOOST_CONCEPT_REQUIRES( ((XYConcept<T>)), (void)) foo(T t) { std::cout << "XYConcept works!" << std::endl; } int main() { struct { int x; } xtest; struct { int x, y; } xytest; foo(xtest); foo(xytest); return 0; } Expected output: XConcept works! XYConcept works! Can anyone help me with this? Att. Neuton Jr
participants (1)
-
Neuton de Oliveira Braga Júnior