Skip to content

Please compare to C++17's declaration-in-if in the readme #63

@stevecotton

Description

@stevecotton

For the readme's "For example, instead of writing this code:", the example could also be written using C++17's declaration-in-if syntax:

std::optional<image> get_cute_cat (const image& img) {
    if (auto cropped = crop_to_cat(img)) {
        if (auto with_tie = add_bow_tie(*cropped)) {
            if (auto with_sparkles = make_eyes_sparkle(*with_tie)) {
                return add_rainbow(make_smaller(*with_sparkles));
            }
        }
    }

    return std::nullopt;
}

I'm looking at the library because it's been mentioned on a Debian mailing list, but AFAICS the syntax built into C++17 already provides these benefits.

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