samedi 25 juillet 2020

Initialise class template depending on another template

This is what I have tried thus far:

Here is my code:

template<typename T1>
struct Foo 
{
    template<typename T2>
    using MyPair = std::pair<T1, T2>;
    using MyPairs = std::vector<MyPair>;

    Foo() 
    {
        //if T1 is an int, then I want T2 to be a double.
        //if T1 is a float, then I want T2 to be an int.
    }
};

I would like T2 to be a double if T1 is an int. I would like T2 to be an int if T1 is a float.

How am I able to do this?

Aucun commentaire:

Enregistrer un commentaire