martinmoene / value-ptr-lite

value-ptr-lite - A C++ smart-pointer with value semantics for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
48 stars 14 forks source link

Clashes with nonstd::variant by inplace_t types while compiling with MSVS 2017 #5

Open flexferrum opened 6 years ago

flexferrum commented 6 years ago

The simple source:

#include <utility>
#include <iostream>
#include <nonstd/value_ptr.hpp>
#include <nonstd/variant.hpp>

struct TestStruct
{
    int a;
};

int main()
{
    nonstd::value_ptr<TestStruct> tmp(TestStruct{10});
    // std::variant<int, char> var;
    nonstd::variant<int, char> var2;

    std::cout << tmp->a << " " << var.index() << " " << var2.index() << std::endl;

    return 0;
}

It fails to compile with MSVS 2017 (19.15.26732.1 x64) either with 14th or 17th standard set. If I swap includes of value_ptr.hpp and variant.hpp everything goes fine. The similar bug is here: https://onedrive.live.com/?authkey=%21AMtLKi_uWVjLFbM&cid=ECB37B93BA908BCE&id=ECB37B93BA908BCE%2116696&parId=root&o=OneUp (line 2356).

Came from this discussion: https://github.com/flexferrum/Jinja2Cpp/issues/80

flexferrum commented 6 years ago

Looks like my fault. Haven't updated my fork for month and a half. Updated version compiles pretty well.

martinmoene commented 6 years ago

Yet I think the mechanism for selection of std::in_place or non::std in_place in nonstd::any, optional, variant and value_ptr can be inproved in the face of C++17 and later.

martinmoene commented 6 years ago

See also Provide nonstd::in_place separately from std::any and ilk.