mohitanand001 / underscore_cpp

underscore_cpp
MIT License
7 stars 30 forks source link

An attempt to decrease passing containers around. #85

Closed mohitanand001 closed 6 years ago

mohitanand001 commented 6 years ago

@gubatron @Gotham13121997 Since passing containers around is expensive (and we want to minimize it), but required in some functions, shall we have an option like

template <typename Container>
 Container set_union(const Container &container1, const Container &container2, Container &result)

where result would be a container passed by the user, which can have the final result inside it.

gubatron commented 6 years ago

Short answer: no, let's keep things functional.

Long answer: In this instance, the result is a new container which is created in the function, you'd only be passing an empty container to fill it out, no real gain in memory performance.

Also, I'd say that you want to stay away from that old C-style of coding and we should stick to a more functional style of programming.

If we have methods that cause the container parameters to mutate, we should then do so, but you already know that the input parameter will be mutated, so you know in advance it's the output.

Another benefit to keeping the method interfaces functional is that we can have versions of the functions that take variadic parameters.