mercredi 28 mars 2018

Do I have to declare each operator overload to be able to able to use it for type T?

Let's say I have a key value class as so

template <typename T>
class KeyValue
{
private:
   std::string Key;
   T Value;

public:
    void operator=(const T &value) 
    {
        this->Value = value;
    }
};

I would have to declare each operator that I want to support on my type T property. Is there a way to automatically have most if not all operators work? It's just typing so it's not a huge deal but it would be cool if I can do something. Now I can write an essay as to why I want to do this, why am I not using a pair? etc.. I will say that I am exploring a small piece in a larger picture and I just don't want to type every operator if it can be avoided.

Aucun commentaire:

Enregistrer un commentaire