lundi 1 avril 2019

How to forward constructor arguments to boost::optional

I have the following simple struct:

struct X
{
    X(std::string name, int value): name_(name), value_(value){}

    std::string name_;
    int value_;
};

I would like to use it with boost optional without copying. Here is one option:

boost::optional<X> op;
op.emplace("abc", 5);

Is it possible without using emplace function ? (I mean one line expression)

Aucun commentaire:

Enregistrer un commentaire