strict-variant icon indicating copy to clipboard operation
strict-variant copied to clipboard

Combine the lambda of visitor

Open erakis opened this issue 6 years ago • 1 comments

Hi,

Would you mine adding a make_visitor as seen on this page to allow using lambada with multiple type handling ? Ref: https://bitbashing.io/std-visit.html

Ex :

[](auto& arg) {
    using T = std::decay_t<decltype(arg)>;

    if constexpr (std::is_same_v<T, string>) {
        printf("string: %s\n", arg.c_str());
        // ...
    }
    else if constexpr (std::is_same_v<T, int>) {
        printf("integer: %d\n", arg);
        // ...
    }
    else if constexpr (std::is_same_v<T, bool>) {
        printf("bool: %d\n", arg);
        // ...
    }
}

erakis avatar Mar 12 '18 19:03 erakis

Yeah I can do that, but I think it's got some other names also:

https://arne-mertz.de/2018/05/overload-build-a-variant-visitor-on-the-fly/#The_stdoverload_proposal

make_visitor is not a bad one though and it won't conflict with std I guess

Sorry I missed this issue until now

cbeck88 avatar Dec 03 '18 21:12 cbeck88