|
|
|
@ -20,6 +20,14 @@ void read_fake(const Cow& clone)
|
|
|
|
|
printf("read_fake: %s\n", clone.area_as<char>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void moving_cow(Cow moved)
|
|
|
|
|
{
|
|
|
|
|
auto moved_clone = moved.reinterpret<char>();
|
|
|
|
|
strncpy(&moved_clone, "Ummmm....", moved_clone.size());
|
|
|
|
|
|
|
|
|
|
read_fake(moved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Cow real(4096);
|
|
|
|
@ -40,5 +48,10 @@ int main()
|
|
|
|
|
read_fake(real);
|
|
|
|
|
|
|
|
|
|
printf("First byte of: real = %x, fake = %x\n", real[0], clone[0]);
|
|
|
|
|
moving_cow(std::move(real)); //moving real is fine
|
|
|
|
|
// <-- real is now dropped. But `clone` still holds Rc to _inner (cow_t).
|
|
|
|
|
printf("First byte of: fake = %x\n", clone[0]);
|
|
|
|
|
read_fake(clone); //clone still functions because of refcount on origin.
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|