When to use std::make_shared_for_overwrite?

Viewed 742
1 Answers

std::make_shared() value initialises the object(s) it creates, which might be an unnecessary step if you intend to assign values over them later.

std::make_shared_for_overwrite() default initialises the object(s) it creates.

The difference only matters for (sub-)objects of fundamental types, where there is no initialiser.

std::make_shared<int[1000][1000]>() will allocate and zero a million ints std::make_shared_for_overwrite<int[1000][1000]>() will allocate a million ints

Related