mercredi 1 juillet 2015

Alias to member function

Consider the following structs :

struct A{
    template <size_t N>
    int * get();
};

struct B{
   A a;
};

if I have an object b, I can call b.a.get<0>(), I would like to make that call more simple, something like b.get_0()

I did this :

struct B{
       A a;
       decltype(std::bind(static_cast<int*(A::*)()>(&A::get<0>), tr1::ref(a))) get_0 
        = std::bind(static_cast<int*(A::*)()>(&A::get<0>), std::ref(a));
    };

this is working, but not beautiful ...

I want to simplify this, I can add as many aliases in struct A, as few as possible in B :

struct B{
       A a;
       // Some aliases
       return_type<0> get_0 
        = call<0>;
    };

Aucun commentaire:

Enregistrer un commentaire