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

Compile error on C++14 #48

Open soroush opened 1 year ago

soroush commented 1 year ago

Hi

The following code does not compile using MSVC 142 (19.35.32215 from VS 2022) using C++14 standard

#include <iostream>
#include "variant.hpp"

int main() {
    std::pair<std::string, nonstd::variant<std::string>> y2 = {"a", "b"};
}

It hits the error C3445: copy-list-initialization of 'std::pair<std::string, nonstd::blah>... which we assume is because in our setup, this is observed as false:

std::is_convertible<const char*, nonstd::variant<std::string>>::value

While the same for std::variant evaluates to true. This then makes std::pair constructor to be explicit which in turn removes the possibility of using a wide range of valid codes like this:

    using foo = nonstd::variant<std::string>;
    using bar = std::map<std::string, foo>;
    auto zoo = bar{{"hello", "world"}};
martinmoene commented 1 year ago

Thank you for making me aware of this. Takes some staring at it...

soroush commented 1 year ago

Any workarounds yet?