R
rep_movsd
I have a utility class that lets you do something like this :
TDelimStream<char> ds(cerr, ", ");
ds << 1 << 2 << 3 << 4;
prints :
1, 2, 3, 4
Now I wish I could have it put an std::endl automatically, I have a
hunch there's no way to do this.... There seem to be no suitable
operators that have less precedence than <<
Any ideas?
Here is the implementation :
template<typename ELEM = char>
struct TDelimStream
{
typedef std::basic_ostream<ELEM, std::char_traits<ELEM> > ostream;
ostream &m_stream;
string m_sDelim;
TUntil<1> m_once;
TDelimStream(ostream &stream, const string& sDelim) :
m_stream(stream), m_sDelim(sDelim)
{
}
//////////////////////////////////////////////////////////////////////////
};
template<typename T, typename T2>
TDelimStream<T> &operator<<(TDelimStream<T> &p, const T2& val)
{
if(p.m_once.occurred())
{
p.m_stream << p.m_sDelim;
}
p.m_stream << val;
return p;
}
//////////////////////////////////////////////////////////////////////////
TDelimStream<char> ds(cerr, ", ");
ds << 1 << 2 << 3 << 4;
prints :
1, 2, 3, 4
Now I wish I could have it put an std::endl automatically, I have a
hunch there's no way to do this.... There seem to be no suitable
operators that have less precedence than <<
Any ideas?
Here is the implementation :
template<typename ELEM = char>
struct TDelimStream
{
typedef std::basic_ostream<ELEM, std::char_traits<ELEM> > ostream;
ostream &m_stream;
string m_sDelim;
TUntil<1> m_once;
TDelimStream(ostream &stream, const string& sDelim) :
m_stream(stream), m_sDelim(sDelim)
{
}
//////////////////////////////////////////////////////////////////////////
};
template<typename T, typename T2>
TDelimStream<T> &operator<<(TDelimStream<T> &p, const T2& val)
{
if(p.m_once.occurred())
{
p.m_stream << p.m_sDelim;
}
p.m_stream << val;
return p;
}
//////////////////////////////////////////////////////////////////////////