Boost C++ Libraries: Ticket #7775: Allow algorithm::join to accept a container of char* https://svn.boost.org/trac10/ticket/7775 <p> Sometimes it would be nice to join strings in this way: </p> <pre class="wiki">const char *names[] = {"Jane", "John", "Kate", "Kyle"}; std::cout &lt;&lt; boost::algorithm::join(names, ", ") &lt;&lt; std::endl; </pre><p> Can join be fixed to accept char*[]? </p> <p> I think that one possible change would be in using a wrapper for a range_value&lt;&gt; that would return std::basic_string for a range_value&lt;&gt;::type which is a T* and range_value&lt;&gt;::type if it is something else. Anyway invoking join with a range value of T* with T not representing a character data is erroneous. </p> <p> Another option is to use the result of evaluation of operator+(range_value, separator) - so a user can pass std::string in the case above to make it valid, but I'm not sure if this is possible and/or portable. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7775 Trac 1.4.3 Marshall Clow Tue, 12 Feb 2013 19:13:06 GMT <link>https://svn.boost.org/trac10/ticket/7775#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7775#comment:1</guid> <description> <p> The problem is not creating from an array of <code>char *</code>, but from a container of <code>char *</code>. </p> <p> <code>boost::algorithm::join</code> takes a "container (A) of containers (B)" and returns a "container (B)". </p> <p> When the (B) container is just "char *", it has no facility for creating such a container. </p> <pre class="wiki">std::string arr[] = { "Hi", "Mom" }; boost::algorithm::join(arr, ", "); </pre><p> works fine (and returns a <code>std::string</code>) </p> <pre class="wiki">std::vector&lt;char *&gt; strs; strs.push_back("Hello"); strs.push_back("World!"); boost::algorithm::join(strs, ", "); </pre><p> does not. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sergey Mitsyn <svm at jinr.ru></dc:creator> <pubDate>Wed, 13 Feb 2013 05:51:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7775#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7775#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7775#comment:1" title="Comment 1">marshall</a>: </p> <blockquote class="citation"> <p> The problem is not creating from an array of <code>char *</code>, but from a container of <code>char *</code>. </p> <p> <code>boost::algorithm::join</code> takes a "container (A) of containers (B)" and returns a "container (B)". </p> <p> When the (B) container is just "char *", it has no facility for creating such a container. </p> <pre class="wiki">std::string arr[] = { "Hi", "Mom" }; boost::algorithm::join(arr, ", "); </pre><p> works fine (and returns a <code>std::string</code>) </p> </blockquote> <p> Yep, that works perfectly! Didn't know c++03 allows that. Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 13 Feb 2013 14:11:44 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7775#comment:3 https://svn.boost.org/trac10/ticket/7775#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> Ticket