martinmoene / variant-lite

variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
239 stars 26 forks source link

nonstd::visit does not work in VisualStudio #2

Closed tower120 closed 7 years ago

tower120 commented 7 years ago

The following code does not compiles in Visual Studio 2017:

struct A {
    int x = 1;
};
struct B {
    int x = 2;
};
struct C {
    int x = 3;
};

nonstd::variant<A, B, C> v;

int main()
{
    v = A();
    nonstd::visit([](auto&& e) {

    }, v);

    return 0;
}
martinmoene commented 7 years ago

Note 1: visitor is limited to always return a Variant (just above this).

nonstd::visit( [&](auto&& e){ return v; }, v );

Due to pre-C++17 language limitations (or mine), variant-lite's visitor must return the variant.

tower120 commented 7 years ago

This is non standart-compatible behaviour. But I understood you.