jeudi 31 mai 2018

how to do optional nullable template wrapper

How to represent a type which is optional and also nullable, i.e. can be explicitly set to null?

Is there something in the standard library or boost?

Otherwise I thought to do something like:

template<typename T>
class optnull : public optional<optional<T>>
{
public:
    bool isSet() { ...; }
    bool isNull() { ...; }
    T& get() { ...; }
};

is that good?

Aucun commentaire:

Enregistrer un commentaire