lundi 2 mars 2020

How to get pointer out of boost::optional?

I want to get the pointer that is stored in my boost::optional. Is there a preferred way to do this? What I got now looks quite cumbersome (dereference and reference again):


// a function I want to call
void processFrame(const Frame* frame) { ... }

// this is how I get my optional
boost::optional<Frame> frame = video.getFrame();

// this is my call so far, which I am not satisfied with (looks strange)
processFrame(frame ? &(*frame) : nullptr);

Aucun commentaire:

Enregistrer un commentaire