Closed jpf91 closed 4 years ago
I'm not sure the smart pointers should satisfy template constraints on the enclosed type. It's not the case in C++:
auto ints = make_shared<vector<int>>();
ints->push_back(4);
ints->push_back(5);
ints->push_back(6);
for(auto i: *ints) {
cout << i << endl;
}
Notice that ints
must be dereferenced in the range for loop. It won't compile with for(auti i: ints)
. Likewise, this D code works:
foreach(i; *rc) {}
foreach(i; *un) {}
Example:
Same thing happens if front is a data member. For unique it's probably not possible to fix this, because of this DMD problem: https://issues.dlang.org/show_bug.cgi?id=15413 But I don't know why it doesn't work for RefCounted.