Project

General

Profile

Feature #2334

Updated by Christopher Green about 7 years ago

I have used the following template a number of times recently. recent. I use it as a handy notation to print the contents of a vector (often in a debugging context):

The template allows me to:<pre> to:
std::vector<T> v; // where T has operator<<()
// fill v.
std:: cout << v << endl;</pre> endl;

The fragment is:<pre><code class="cplusplus"> is:

template <class T>
inline std::ostream& operator<<(std::ostream& ost,
typename std::vector<T> const& v ){
for ( typename std::vector<T>::const_iterator i=v.begin(), e=v.end();
i != e; ++i ){
ost << *i;
}
return ost;
}</code></pre> }

Is this generally a safe practice?
If so, is it a candidate for inclusion in cetlib in header named, perhaps, cet/VectorPrinter.h ?

Back