0

Sorry if this has been answered already, but I've been looking for hours and can't find anyone who's tried something quite like this. I'm trying to do something like the following, but I have no earthly idea what the syntax should be for Entity_Aspectual.

template<class Context>
class Trait1_Barsome
{
};

template<class Context>
class Trait1_Foobish
{
};

template<class Context>
class Trait2_Barsome
{
};

template<class Context>
class Trait2_Foobish
{
};

class Aspect_Foobish
{
public:
    template<class Context>
    using Trait1Policy = Trait1_Foobish<Context>;
    template<class Context>
    using Trait2Policy = Trait2_Foobish<Context>;
};

class Aspect_Barsome
{
public:
    template<class Context>
    using Trait1Policy = Trait1_Barsome<Context>;
    template<class Context>
    using Trait2Policy = Trait2_Barsome<Context>;
};

template<class Context,
         template<class> class Trait1,
         template<class> class Trait2>
class Entity:
    public Trait1<Context>,
    public Trait2<Context>
{
};

class ActualContext {};

template<class Context,
         class Aspect>
using Entity_Aspectual = Entity<Context,
                                typename Aspect::Trait1Policy,
                                typename Aspect::Trait2Policy>;

int main()
{
    Entity_Aspectual<ActualContext, Aspect_Foobish> foobishEntity;
    Entity_Aspectual<ActualContext, Aspect_Barsome> barsomeEntity;

    return 0;
}

It seems trivial in this case, but in my application the type of specialization you'd see in Entity is far more complex and would make Entity_Aspectual extremely verbose if I tried a solution like the following:

template<class Trait1,
         class Trait2>
class Entity:
    public Trait1,
    public Trait2
{
};

template<class Context,
         class Aspect>
using Entity_Aspectual = Entity<typename Aspect::template Trait1Policy<Context>,
                                typename Aspect::template Trait2Policy<Context>>;
Alex Whitt
  • 13
  • 3
  • 1
    It is not a type, but a template: `Aspect::template Trait1Policy`. – dyp Oct 23 '14 at 19:51
  • Please try to boil down your problem to a minimal, complete example. [This much](http://coliru.stacked-crooked.com/a/846436be56a3280f) might be sufficient. – dyp Oct 23 '14 at 19:52
  • Welcome to SO, as you seem to be a new user I'd suggest you read the [How to ask](http://stackoverflow.com/help/how-to-ask) introduction as I am currently not able to recognize the actual question. It always helps to finish a question with a sentence ending in a question mark to highlight the actual problem at hand. – Sim Oct 23 '14 at 19:53
  • Thank you, dyp! I wish I had found which question this was a duplicate of T_T Oh and thanks for the posting tips, I'll keep them in mind! – Alex Whitt Oct 23 '14 at 20:34

0 Answers0