I'm trying to use std::is_copy_assignable_v
to detect whether a class has Class& operator=(const Class&)
:
#include <iostream>
#include <memory>
#include <unordered_map>
#include <map>
int main() {
// All of them are true, Why???
std::cout << std::is_copy_assignable_v<std::unordered_map<int, int>> << std::endl;
std::cout << std::is_copy_assignable_v<std::unordered_map<int, std::unique_ptr<int>>> << std::endl;
std::cout << std::is_copy_assignable_v<std::unordered_map<std::unique_ptr<int>, std::unique_ptr<int>>> << std::endl;
std::cout << std::is_copy_assignable_v<std::unordered_map<std::unique_ptr<int>, int>> << std::endl;
return 0;
}
std::unique_ptr
will delete it's copy assignment function and so will std::unordered_map
, isn't it?
And the compile say it has copy assignment, but when I try:
std::unordered_map<std::unique_ptr<int>, int> a;
std::unordered_map<std::unique_ptr<int>, int> b;
a = b;
It can't compile.
This doesn't seem to be a compiler problem either(try it on godbolt).