1

I've made use of interesting composition components like this one:

callable composition

And I've successfully used this in a context where I dynamically instantiate various objects, and call a virtual function on them getCallable() which returns a std::bind of to a member function. I then use the composition concept in the link above with the operator * to compose all of them into one callable. This works fine and with a single function call I get a long chain of member function calls to my objects. I'm trying to achieve something similar but at compile time when I know what my call chain should be (two object A's followed by a B, say). Something like this:

template <class T...>
struct CallChain
{
    static ?someComposedType? get();
};

I want to have a few variations of fully static const structs like this:

struct ArgStructX
{
    static const int x = 8;
    static const bool y = false;
    static const float z = 17.6;
};

And a few callable classes like this:

struct CallableX
{
    CallableX(const ArgStructX&);
    void operator()();
};

And then I want to be able to say something like this (for example):

template class CallChain<CallableX, ArgStructX, CallableY, ArgStructY>; //explicit instantiate in some C file

typedef template CallChain<CallableX, ArgStructX, CallableY, ArgStructY> MyChain;
auto F = MyChain::get();

What I'm trying to achieve at the last line above is for that to create a CallableX by passing it an ArgStructX, a CallableY by passing it an ArgStructY, and then internally compose them (as per the link above, for example) and give me back the final callable. So then if I said F() it would be CallableY(CallableX()). If done compile time, there should be no indirection (as opposed to my dynamic approach) in the final call chain. How could I go about this?

Community
  • 1
  • 1
Palace Chan
  • 8,845
  • 11
  • 41
  • 93

0 Answers0