<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: The Complete Guide to Building Strings In C++: From &#8220;Hello World&#8221; Up To Boost Karma	</title>
	<atom:link href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Tue, 28 Aug 2018 11:57:32 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: Сергей Шамов		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-731</link>

		<dc:creator><![CDATA[Сергей Шамов]]></dc:creator>
		<pubDate>Wed, 27 Dec 2017 14:15:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-731</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-730&quot;&gt;Jonathan Boccara&lt;/a&gt;.

No, state is not duplicated while the algorithm traversing a sequence. The inner loop uses the same instance of output iterator. But actually in practice I use totally different approach.
&lt;pre&gt;&lt;code&gt;
template &#060;typename CharT = char&#062;
class smart_separator
{
    using ostream_type = basic_ostream&#060;CharT, char_traits&#060;CharT&#062;&#062;;
 
public:
    smart_separator(const CharT* value) : value_(value), first_(true) { }
 
    friend ostream_type&#038; operator &#060;&#060;(ostream_type&#038; os, smart_separator&#038; sep) {
        if (sep.first_) sep.first_ = false; else os &#060;&#060; sep.value_;
        return os;
    }
 
private:
    const CharT* value_;
    bool         first_;
};
 
int main()
{
    vector&#060;int&#062; numbers = {1, 2, 3, 4, 5};
 
    smart_separator&#060;&#062; sep(&#034;,&#034;);
    for (auto number : numbers) cout &#060;&#060; sep &#060;&#060; number;
}
&lt;/code&gt;&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-730">Jonathan Boccara</a>.</p>
<p>No, state is not duplicated while the algorithm traversing a sequence. The inner loop uses the same instance of output iterator. But actually in practice I use totally different approach.</p>
<pre><code>
template &lt;typename CharT = char&gt;
class smart_separator
{
    using ostream_type = basic_ostream&lt;CharT, char_traits&lt;CharT&gt;&gt;;
 
public:
    smart_separator(const CharT* value) : value_(value), first_(true) { }
 
    friend ostream_type&amp; operator &lt;&lt;(ostream_type&amp; os, smart_separator&amp; sep) {
        if (sep.first_) sep.first_ = false; else os &lt;&lt; sep.value_;
        return os;
    }
 
private:
    const CharT* value_;
    bool         first_;
};
 
int main()
{
    vector&lt;int&gt; numbers = {1, 2, 3, 4, 5};
 
    smart_separator&lt;&gt; sep(&quot;,&quot;);
    for (auto number : numbers) cout &lt;&lt; sep &lt;&lt; number;
}
</code></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-730</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Wed, 27 Dec 2017 13:55:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-730</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-729&quot;&gt;Сергей Шамов&lt;/a&gt;.

If it&#039;s copied once when passing it to the algorithm it&#039;s fine, but if the algorithms can hold several instances of the output iterator the state would indeed be duplicated.
Anyway that&#039;s a nice trial. I&#039;m sure that&#039;s the starting point of a better solution. Maybe with std::ref? Or it that overkill?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-729">Сергей Шамов</a>.</p>
<p>If it&#8217;s copied once when passing it to the algorithm it&#8217;s fine, but if the algorithms can hold several instances of the output iterator the state would indeed be duplicated.<br />
Anyway that&#8217;s a nice trial. I&#8217;m sure that&#8217;s the starting point of a better solution. Maybe with std::ref? Or it that overkill?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Сергей Шамов		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-729</link>

		<dc:creator><![CDATA[Сергей Шамов]]></dc:creator>
		<pubDate>Wed, 27 Dec 2017 11:26:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-729</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-728&quot;&gt;Jonathan Boccara&lt;/a&gt;.

Unfortunaly, no. Iterator is copied every time. Moreover, if it&#039;s non-copyable, the code won&#039;t compile at all.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-728">Jonathan Boccara</a>.</p>
<p>Unfortunaly, no. Iterator is copied every time. Moreover, if it&#8217;s non-copyable, the code won&#8217;t compile at all.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-728</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Wed, 27 Dec 2017 11:09:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-728</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-727&quot;&gt;Сергей Шамов&lt;/a&gt;.

Neat! I like the idea.
Do you know if the STL algorithms are sure not to copy the output iterator (to be sure that the state &quot;first_&quot; stays consitently in one place)?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-727">Сергей Шамов</a>.</p>
<p>Neat! I like the idea.<br />
Do you know if the STL algorithms are sure not to copy the output iterator (to be sure that the state &#8220;first_&#8221; stays consitently in one place)?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Сергей Шамов		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-727</link>

		<dc:creator><![CDATA[Сергей Шамов]]></dc:creator>
		<pubDate>Wed, 27 Dec 2017 08:51:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-727</guid>

					<description><![CDATA[It&#039;s not so hard to make ostream_iterator, that won&#039;t adding last separator.
&lt;pre&gt;&lt;code&gt;
template &#060;typename T, typename CharT = char&#062;
class infix_ostream_iterator : public iterator&#060;output_iterator_tag, void, void, void, void&#062;
{
    using self_type = infix_ostream_iterator&#060;T, CharT&#062;;
    using ostream_type = basic_ostream&#060;CharT, char_traits&#060;CharT&#062;&#062;;
 
public:
    infix_ostream_iterator(ostream_type&#038; os, const CharT* sep)
        : os_(os), sep_(sep), first_(true)
    { }
 
    self_type&#038; operator*() { return *this; }
    self_type&#038; operator++() { return *this; }
 
    self_type&#038; operator=(const T&#038; item) {
        if (!first_) os_ &#060;&#060; sep_; else first_ = false;
        os_ &#060;&#060; item;
 
        return *this;
    }
 
private:
    ostream_type&#038; os_;
    const CharT*  sep_;
    bool          first_;
};&lt;/code&gt;&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not so hard to make ostream_iterator, that won&#8217;t adding last separator.</p>
<pre><code>
template &lt;typename T, typename CharT = char&gt;
class infix_ostream_iterator : public iterator&lt;output_iterator_tag, void, void, void, void&gt;
{
    using self_type = infix_ostream_iterator&lt;T, CharT&gt;;
    using ostream_type = basic_ostream&lt;CharT, char_traits&lt;CharT&gt;&gt;;
 
public:
    infix_ostream_iterator(ostream_type&amp; os, const CharT* sep)
        : os_(os), sep_(sep), first_(true)
    { }
 
    self_type&amp; operator*() { return *this; }
    self_type&amp; operator++() { return *this; }
 
    self_type&amp; operator=(const T&amp; item) {
        if (!first_) os_ &lt;&lt; sep_; else first_ = false;
        os_ &lt;&lt; item;
 
        return *this;
    }
 
private:
    ostream_type&amp; os_;
    const CharT*  sep_;
    bool          first_;
};</code></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Kelvin Wekesa		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-726</link>

		<dc:creator><![CDATA[Kelvin Wekesa]]></dc:creator>
		<pubDate>Fri, 22 Dec 2017 09:22:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-726</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-723&quot;&gt;sehe&lt;/a&gt;.

My bad.
&quot;It ain&#039;t what you don&#039;t know that gets you into trouble. It&#039;s what you know for sure that just ain&#039;t so&quot;

If this particular situation &#062;loading a file&#039;s contents into a std::string&#060; had cropped up in a real project am working on, I would have introduced a subtle bug... thanks for calling me out its how we learn]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-723">sehe</a>.</p>
<p>My bad.<br />
&#8220;It ain&#8217;t what you don&#8217;t know that gets you into trouble. It&#8217;s what you know for sure that just ain&#8217;t so&#8221;</p>
<p>If this particular situation &gt;loading a file&#8217;s contents into a std::string&lt; had cropped up in a real project am working on, I would have introduced a subtle bug&#8230; thanks for calling me out its how we learn</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-725</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Thu, 21 Dec 2017 21:36:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-725</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-722&quot;&gt;Colin Pitrat&lt;/a&gt;.

to_string was added in C++11 so it&#039;s in &quot;modern C++&quot; :) I see your point, and I&#039;m not sure why this isn&#039;t an overloaded function template.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-722">Colin Pitrat</a>.</p>
<p>to_string was added in C++11 so it&#8217;s in &#8220;modern C++&#8221; 🙂 I see your point, and I&#8217;m not sure why this isn&#8217;t an overloaded function template.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: sehe		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-723</link>

		<dc:creator><![CDATA[sehe]]></dc:creator>
		<pubDate>Thu, 21 Dec 2017 20:14:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-723</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-718&quot;&gt;Kelvin Wekesa&lt;/a&gt;.

Avoid strong advice. Especially if untested. Why not hit the docs or try it? http://coliru.stacked-crooked.com/a/2f8afdcc448eda09]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-718">Kelvin Wekesa</a>.</p>
<p>Avoid strong advice. Especially if untested. Why not hit the docs or try it? <a href="http://coliru.stacked-crooked.com/a/2f8afdcc448eda09" rel="nofollow ugc">http://coliru.stacked-crooked.com/a/2f8afdcc448eda09</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Colin Pitrat		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-722</link>

		<dc:creator><![CDATA[Colin Pitrat]]></dc:creator>
		<pubDate>Thu, 21 Dec 2017 20:06:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-722</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-720&quot;&gt;Jonathan Boccara&lt;/a&gt;.

But were to_string written today, would the committee make it a template function (to allow extending it to custom types) ?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-720">Jonathan Boccara</a>.</p>
<p>But were to_string written today, would the committee make it a template function (to allow extending it to custom types) ?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-721</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Thu, 21 Dec 2017 18:01:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1143#comment-721</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-710&quot;&gt;Björn Fahller&lt;/a&gt;.

ostream_joiner (suggested by sv90 in the above &lt;a href=&quot;http://disq.us/p/1ooe324&quot; rel=&quot;nofollow&quot;&gt;comment&lt;/a&gt;) looks good to me. Additionally range-v3 has &lt;a href=&quot;https://github.com/ericniebler/range-v3/blob/master/include/range/v3/view/intersperse.hpp&quot; rel=&quot;nofollow&quot;&gt;intersperse&lt;/a&gt; doing a similar feature I reckon.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/12/19/build-strings-from-plain-string-up-to-boost-karma/#comment-710">Björn Fahller</a>.</p>
<p>ostream_joiner (suggested by sv90 in the above <a href="http://disq.us/p/1ooe324" rel="nofollow">comment</a>) looks good to me. Additionally range-v3 has <a href="https://github.com/ericniebler/range-v3/blob/master/include/range/v3/view/intersperse.hpp" rel="nofollow">intersperse</a> doing a similar feature I reckon.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
