Skip to content

API question: Is there value_or(...) equivalent? #49

@mkucmpro

Description

@mkucmpro

I wanted to know if there exists an API similar to value_or(...) that would allow me to do something like:

struct Something { int interesting{0}; };

int getter() {
    QtPromise::QPromise<Something> promise = ...;  // Obtained somehow

    return promise.wait().value_or(Something{}).interesting;
}

I often find myself doing something similar to:

int getter() {
    QtPromise::QPromise<Something> promise = ...;

    int outerInteresting = 0;
    promise.then([&](const Something& s) { outerInteresting = s.interesting; }.wait();
 
    return outerInteresting;
}

Would an addition like value_or() be useful for the library?

Btw. I was also thinking that to_optional() could also fit my needs but that would require C++17 (and AFAIK the library aims to support C++11). What is the authors' current attitude towards conditional compilation and feature testing (if the compiler supports C++17)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions