mercredi 22 février 2017

Converting PrintContainer Preprocessor Define into Template in C++11

I've got the following preprocessor define:

#define PRINTARRAY(Type, Array, Stream, Separator) \
std::copy(std::begin(Array), std::end(Array), std::ostream_iterator<Type>(Stream, Separator))

I'm wanting to convert this to a template, so it can automatically determine the type for the ostream_iterator, so I don't have to pass it in.

However, I'm wondering what how to do this. My key issues are:

  • Getting this to work with all STL containers
  • Getting this to work with ordinary arrays (which std::begin / end supports?)

I think the key issue is that the ostream_iterator, afaik, needs to have the type of the contained values, and not the type of the container.

Does anyone have any ideas? Thanks.

Aucun commentaire:

Enregistrer un commentaire