I think Boost :: variant is unpacked at 1_54. I am trying to use std :: unique_ptr as a limited type in the boost variant.
According to the documentation 1_54, the variant must be copyable or Move Constructable.
http://www.boost.org/doc/libs/1_54_0/doc/html/variant/reference.html
So, I applied move constructors and disabled copy constructors in my code.
When I try to assign something to a variant, it does not compile. I tried various things, including using std :: move to assign data to a variant of an object, but nothing works. After tracing the stack of compilation errors, I decided the problem was with the .hpp option, where it was trying to back up the rhs data. I would like to know what you guys are thinking and let me know if I am right that the extended documentation is wrong.
Thanks in advance.
I am compiling with vs2010 and using C ++ 11.
Here is my test code:
#include <iostream> #include <memory> #include <utility> #include <vector> #include <string> #pragma warning (push) #pragma warning (disable: 4127 4244 4265 4503 4512 4640 6011) #include <boost/optional.hpp> #include <boost/variant.hpp> #include <boost/ref.hpp> #include <boost/shared_ptr.hpp> #pragma warning (pop) #include <boost/foreach.hpp> #include <boost/format.hpp> using boost::format; using boost::str; using namespace std; class UniqueTest { }; class Foo { public: std::unique_ptr<UniqueTest> testUniquePtr; Foo() { std::cout << "Foo::Foo\n"; } Foo (Foo&& moveData) { } Foo& operator=(Foo&& moveData) { return *this; } private: Foo(Foo& tt); Foo& operator=(const Foo& tt); }; int main() { Foo x = Foo(); boost::variant<std::wstring,Foo> m_result2; std::wstring testString = L"asdf"; m_result2 = testString; //Fails //m_result2 = std::move(testString); //Fails //m_result2 = std::move(x); //Fails boost::get<Foo>(m_result2).testUniquePtr.get (); return 0; }
source share