I am having trouble (compile time, gcc 17) inserting an object in an std::map which contains a unique_ptr. If I use a regular pointer it compiles (if I take the copy constructor out!). Here is the struct containing a unique_ptr. With a ctor, copy ctor, etc, with std::move semantics everywhere. Has anyone seen this issue before?
#include <utility> // std::pair, std::make_pair
#include <string> // std::string
#include <iostream> // std::cout
#include <map>
#include <memory>
struct Struct1
{
Struct1(std::unique_ptr<std::string> pStr)
: pStr_(std::move(pStr)){}
~Struct1(){}
Struct1(Struct1& other)
: pStr_(std::move(other.pStr_)){}
std::unique_ptr<std::string> pStr_;
};
Here is the main. Anything I try I get a "no matching function" for insert
int main () {
std::string s("key");
std::unique_ptr<std::string> pStr = std::make_unique<std::string>("Hello");
std::map<std::string, Struct1>list;
Struct1 ste(std::move(pStr));
std::pair<std::string, Struct1> p(s,ste); // copy into a pair
// std::pair<std::string, Struct1> p(s,std::move(ste)); // copy into a pair
// auto p = std::make_pair(s, std::move(ste));
// auto p = std::make_pair(s, ste);
// list.insert(std::move(p));
list.insert(p);