So, I have a map that stores objects of a class with deleted copy constructor, due to it having a unique_ptr as one of the members. I'm trying to construct this map using std::initializer_list, but I'm getting a huge error, ending with "use of deleted function 'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&)". If I understand correctly, the cause of it is that list's members are not temporaries, but constant references instead, and therefore you just can't move them, neither in an implicit, nor in an explicit way.
Here is the part of the header:
class ExitMessage {
public:
...
ExitMessage( const std::string& text,
std::initializer_list<std::map<std::string, ExitMessage>::value_type> subMessages);
...
private:
std::string _text;
std::unique_ptr<std::map<std::string, ExitMessage>> _subMessages;
...
};
And this is the problematic constructor:
ExitMessage::ExitMessage( const std::string& text,
std::initializer_list<std::map<std::string, ExitMessage>::value_type> subMessages )
: _text( text ), _subMessages( new std::map<std::string, ExitMessage>( subMessages ) ) { }
So, what can I do to make it possible to create an instances of this class using std::initializer_list?