I am trying to use copy assignment in the following case.
There are two classes of patterns: list map
and xpair
.
template <typename Key, typename Value, class Less=xless<Key>>
class listmap {
public:
using key_type = Key;
using mapped_type = Value;
using value_type = xpair<const key_type, mapped_type>;
...
}
template <typename First, typename Second>
struct xpair {
First first{};
Second second{};
xpair(){}
xpair (const First& first, const Second& second):
first(first), second(second) {}
};
In main.cpp I tried to write
using commend = string;
using str_str_map = listmap<string,string>;
using str_str_pair = str_str_map::value_type;
using commend_pair = xpair<commend, str_str_pair>;
int main(...) {
commend_pair cmd_pair;
str_str_pair newPair ("Key", "value");
cmd_pair.second = newPair;
...
}
It gives me an error saying
object of type 'xpair<const std::__1::basic_string<char>,
std::__1::basic_string<char> >' cannot be assigned because its copy
assignment operator is implicitly deleted
If I replaced
using str_str_pair = str_str_map::value_type;
to
using str_str_pair = xpair<string, string>;
Everything works perfectly. Why is this? Shouldn't value_type = xpair<string, string>
?
source
share