Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nice example! I think that can be simplified:

  node a(nil, nil, 0);
  node b(a, a, 2);
  new(&a) node(b, b, 1);
One thing I am not 100% sure about is whether the standard guarantees that those references to the old 'a' are valid references to the new 'a'.

Also, the above works in the general case where there is a nontrivial destructor or when the runtime checks the validity of those references or traverses them at destruction time (might happen when running under a tool looking for memory leaks, for instance, or when using a reference-counting garbage collector under the hood)



The standard doesn’t seem to specify it directly, but I think your simplification is also correct.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: