The problem is really simple. I have a code:
#include <string>
#include <memory>
#include <vector>
#include <boost/variant.hpp>
#include <QVector>
int main() {
QVector<boost::variant<std::unique_ptr<std::string>, int>> qt_vector;
std::string* qt_test = new std::string;
qt_vector.push_back(std::unique_ptr<std::string>(qt_test));
std::vector<boost::variant<std::unique_ptr<std::string>, int>> std_vector;
std::string* std_test = new std::string;
std_vector.push_back(std::unique_ptr<std::string>(std_test));
}
And first version (qt) gives me a compilation error, while std's version works just fine. I have looked on std::vector source code and I think I understood (more or less) what is going there, but I could not find the source code for QVector (I have looked in Qt repository).
The question is: what is the difference between std::vector::push_back
and QVector::push_back
and what can I do in this situation to use QVector
instead of std::vector
.
P.S. I want to have a vector of boost::variant<std::unique_ptr<std::string>, int>
and this example very closely resembles what I'm trying to do in my main code. I'm trying to use QVector
because in all other parts of my app I have also used Qt containers
P.S. Error message is:
use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = std::__cxx11::basic_string<char>; _Dp = std::default_delete<std::__cxx11::basic_string<char> >]’
P.S This question is different from this one because it asks about specific example and provides the context of an issue caused by the problem that was discussed in mentioned question. I also provide a concrete example that could be useful for a person who is trying to understand a problem.