jeudi 10 septembre 2020

Anyway to link mutiple if conditions toghether with c++ template?

What I want is

template<typename T>
void larger(T a, T b){
    if(a.x>b.x&&a.y>b.y&&a.z>b.z) return true;
}

. But , each T may only have some of the x,y,z values, for example

struct Txy{
    double x,y;
}

So for Txy I would only judge by x and y. I know I could specify the template to do so, but with many Ts there's no difference between write a function for each T...

Is there any better way to deal with this problem?

Aucun commentaire:

Enregistrer un commentaire