samedi 28 novembre 2015

How to automate creation of tuples of template classes based on elements of an array?

I have an std::array that is filled with all the types of an enumeration. I'd like to implement my tuples based on this.

class CompBase
{
public:
    enum CompType{
        INPUT,
        GRAPHICS
        // ( + 5-10 additional types)
    };

    static const std::array<CompType, 2> compTypeArr;
};

const std::array<CompBase::CompType, 2> CompBase::compTypeArr =
{
    CompBase::INPUT,
    CompBase::GRAPHICS
};

template<CompBase::CompType compType_e>
class CompHolder {}; // owns one component

template<CompBase::CompType compType_e>
class CompContainer {}; // references N components

class CompInterface
{
    // ...
private:
    std::tuple // I want to automate this,
    <
        CompHolder<CompBase::INPUT>,
        CompHolder<CompBase::GRAPHICS>
    > compHolders;
};

class CompHandler
{
    // ...
private:
    std::tuple // and this process, based on the predefined array
    <
        CompCont<CompBase::INPUT>,
        CompCont<CompBase::GRAPHICS>
    > compContainers;
};

To my understanding std::make_tuple is not even constexpr before c++14 ref so I'm not sure if this is possible at all since I'd need a c++11 method. The presence of the array is I think sort of mandatory because an enumeration alone doesn't provide the necessary functionality for something like this.

Aucun commentaire:

Enregistrer un commentaire