When I cut my teeth on C++03, I saw several popular approaches to writing a function that produces a populated container (A "give me the collection of things" function):
template< typename Container >
void make_collection( std::insert_iterator<Container> );
- This must be implemented in a header file
- The interface doesn't communicate that an empty container is expected.
or:
void make_collection( std::vector<Thing> & );
- This is not container agnostic
- The interface doesn't communicate that an empty container is expected.
or:
std::vector<Thing> make_collection();
- This is not container agnostic
- There are several avenues for unnecessary copying.
Using modern C++ standards, is there a more idiomatic function interface to "produce a populated container"?
Aucun commentaire:
Enregistrer un commentaire