I'm reading about set_intersection
and it appears to expect the user to allocate the correct amount of space (or more) in advance but isn't that strange? In c++ you often use std::vector
which dynamically allocates space on the go. Why would set_intersection
implicitly require allocation of space in advance when it is clearly more effective to allocate based on the resulting data size (dynamically)? Is it in hope to maximize performance when the intersection size is known in advance? What about the common case where there intersection size is not known?
Is there any "magical way" to directly allocate one slot per element added to the vector?