Boost C++ Libraries: Ticket #9287: Additional string_ref constructors https://svn.boost.org/trac10/ticket/9287 <p> From: </p> <ul><li>iterator_range&lt;Char const *&gt; </li><li>std::vector&lt;Char&gt; </li><li>pair of iterators </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9287 Trac 1.4.3 Marshall Clow Tue, 22 Oct 2013 12:29:23 GMT owner, status changed https://svn.boost.org/trac10/ticket/9287#comment:1 https://svn.boost.org/trac10/ticket/9287#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">No-Maintainer</span> to <span class="trac-author">Marshall Clow</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> A string_re refers to a contiguous sequence of characters. </p> <p> An iterator_range is not contiguous. Nor is, in general, a pair of iterators. </p> <p> The contents of a <code>vector&lt;char&gt;</code> are, but you can make a string_ref easily thus: <code>string_ref sr(&amp;*v.begin(), v.size());</code> </p> <p> I don't see a compelling need here. If you have examples, (things that you want to do that are awkward/impossible w/o these constructors) please tell me about them. </p> Ticket anonymous Mon, 29 Dec 2014 18:27:19 GMT <link>https://svn.boost.org/trac10/ticket/9287#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9287#comment:2</guid> <description> <p> I couldn't use string_ref as return value of boost/algorithm/split.hpp because string_ref doesn't provide [b, e) style constructor. This is only annoying thing I can think of current string_ref. Other than that I'm using it everywhere. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Tue, 30 Dec 2014 17:09:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9287#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9287#comment:3</guid> <description> <p> if you have two iterators that you know point to a contiguous sequence in memory you can create a string_ref </p> <blockquote> <p> thus: <code>string_ref sr(&amp;*b, std::distance(b, e));</code> </p> </blockquote> <blockquote> <p> or: <code>string_ref sr(&amp;*b, e - b);</code> </p> </blockquote> </description> <category>Ticket</category> </item> <item> <author>vladimir.krivopalov@…</author> <pubDate>Tue, 12 May 2015 00:57:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9287#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9287#comment:4</guid> <description> <p> Hi, </p> <p> It seems that string_ref really lacks these constructors as cannot work with boost::algorithm::split (a widely used one) without them although std::string which boost::string_ref aims to substitute in such cases fits the requirements of this algorithm perfectly. </p> <p> You're right about that pair of iterators doesn't necessarily point to a contiguous storage, but this may be a requirement for this constructor to follow. Consider the existing constructor: string_ref(CharT* str); it crashes if you pass NULL/nullptr to it, so assumes that the input parameter is non-NULL. But this is not enforced (although here it is even possible to check that). </p> <p> The same could apply for the range-based constructor which would allow for range-based algorithms to chime in. </p> </description> <category>Ticket</category> </item> </channel> </rss>