I would like to have overloading functions such that they are dispatched with boost concepts.
#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;
}
Att.