Boost logo

Boost Users :

Subject: [Boost-users] How to implement overloading functions using boost concepts?
From: Neuton de Oliveira Braga Júnior (neutonjr_at_[hidden])
Date: 2015-01-07 06:46:37


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



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net