dimanche 27 mars 2016

need the following code adapted from std::pair to std::tuple of any lenght

I've got some numerical type, which depends on the input variable types and the operations performed. In order to implement a function, which returns a tuple and calls either one or another function I need the following meta code (merge_tuple) implemented. I'm only able to get this working for std::pair -- see below. The calling function looks like this:

template<typename A, typename B, typename C>
typename merge_typle<
    decltype(ONE_F(A(), B(), C()), 
    decltype(TWO_F(A(), B(), C())
>::type function(const A &_rA, const B &_rB, const C &_rC)
{       if (_rA > _rB)
                return ONE_F(_rA, _rB, _rC);
        else
                return TWO_F(_rA, _rB, _rC);
}

Here is the example implementation for std::pair -- the + operation creates the joint type:

template<typename PAIR0, typename PAIR1>
struct mergePair
{       typedef std::pair<
                decltype(typename PAIR0::first_type() + typename PAIR1::first_type()),
                decltype(typename PAIR0::second_type() + typename PAIR1::second_type())
        > type;
};

Aucun commentaire:

Enregistrer un commentaire