What are the use cases for new elision and new combining, added in C++14? (As per cppreference on new)?

And also:

  • Does limiting them to "replacable allocation functions" mean they only apply if operator new has been replaced? Or does it also apply the to the compiler/library supplied operator new?
  • Can you tell if it's been used, or if it could be used, with some if-constexpr-style code?

For new combining I can guess it would make allocate_shared and make_shared easier to write - if you could actually depend on it being used. (Or could detect at compile time whether it would be used in an if-constexpr.) But if you couldn't depend on it being used or detect it you'd have to write those functions the "old-fashioned" way I guess, with some kind of placement new and then just computing pointers to pieces of it.

For new elision, I'm not sure what the use case would be. Compiler discovers something is small enough to fit on the stack (and makes an assumption that the stack won't overflow!) plus discovers its lifetime is deterministic and scoped and so places it in some stack frame with an overlapping scope? What would an actual example of this kind of thing be that's in common use? Or any example in common use?

0

There are 0 best solutions below