Boost C++ Libraries: Ticket #12859: std::string_view as token https://svn.boost.org/trac10/ticket/12859 <p> When I use <code>std::string_view</code> as a token for the <code>tokenizer</code>, I get an error because it attempts to construct a <code>std::string_view</code> with two iterators, which it doesn't support. </p> <p> It'd be very nice to support this efficiency-enhacing type by, perhaphs, constructing the token from the underlying character array and a size when two iterators would be ill-formed. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12859 Trac 1.4.3 damian.meden@… Mon, 27 Feb 2017 16:00:16 GMT <link>https://svn.boost.org/trac10/ticket/12859#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12859#comment:1</guid> <description> <p> Hi, please provide more information on what you are trying to achieve? a code sample of would be great(<a class="missing wiki">TokenizerFunc</a>, etc). There are few things you can do with a string_view, but I do not want to do any answer before seeing what you are trying to. </p> <p> Thanks Dam. </p> </description> <category>Ticket</category> </item> <item> <author>Johel Ernesto Guerrero Peña <johelegp@…></author> <pubDate>Wed, 01 Mar 2017 14:33:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12859#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12859#comment:2</guid> <description> <p> This is my particular use case: </p> <pre class="wiki">auto tokenize(std::string_view to_tokenize, const char* separators) { using TokenizerFunction = boost::char_separator&lt;char&gt;; using Tokenizer = boost::tokenizer&lt; TokenizerFunction, std::string_view::iterator, std::string_view&gt;; return Tokenizer{to_tokenize, TokenizerFunction{separators}}; } </pre><p> I want the Tokenizer to recognize that the token type is not constructible from two iterators, and try to construct it from a {pointer,size} pair instead. </p> </description> <category>Ticket</category> </item> <item> <author>Dam <damian.meden@…></author> <pubDate>Tue, 25 Apr 2017 20:22:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12859#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12859#comment:3</guid> <description> <p> Few things here, </p> <p> Base on what the tokenizer is, which basically it's a non owning helper that relies on the fact that someone else owns the std::string, and the connection between the owner and the tokenizer class is a pure pair of iterator, this make me think that it can be a little bit ambiguous, like, adding one layer between the std::string and the tokenizer, so instead of : Std::string -&gt; boost::tokenizer now it will become std::string -&gt; std::string_view -&gt; boost::tokenizer. See my point? This could be a good discussion, <strong>I would like to know your thoughts about this.</strong> Also, from top of my mind I can think that this is still in most compilers experimental features, so that may be an issue to deal with at boost level. I would check that deep. </p> <p> Anyway, I did play a little with this and I came up with some POC, which can’t be added to boost anyway as it wasn’t properly tested, but at least it helped me to see how it may look like. You can check the diff here -&gt; <a class="ext-link" href="https://github.com/boostorg/tokenizer/compare/develop...dmeden:not_safe_string_view_use_v1"><span class="icon">​</span>https://github.com/boostorg/tokenizer/compare/develop...dmeden:not_safe_string_view_use_v1</a> </p> <p> Tested with GCC 6.3. </p> <p> <strong>Again, this code is not boost ready yet,</strong> there are many things(iterators, etc) that needs to be tested and validated that I didn’t put it into the code yet. </p> <p> Thanks, Dam </p> </description> <category>Ticket</category> </item> <item> <author>Johel Ernesto Guerrero Peña <johelegp@…></author> <pubDate>Sun, 30 Apr 2017 16:47:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12859#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12859#comment:4</guid> <description> <p> I'm starting to think that its better to leave the code as-is. This problem might be better solved elsewhere, like a <code>std::string_view</code> wrapper constructible from a pair of iterators. Does this answer your RFC? </p> </description> <category>Ticket</category> </item> <item> <author>Dam <damian.meden@…></author> <pubDate>Sun, 30 Apr 2017 19:42:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12859#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12859#comment:5</guid> <description> <p> There was a discussion about that (having a constructor that takes a pair of iterators) in the standard: </p> <ul><li><a class="ext-link" href="https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/string_view$20iterator/std-proposals/6X6_IjfzdYI/-Um3vQAZEwAJ"><span class="icon">​</span>https://groups.google.com/a/isocpp.org/forum/?fromgroups#!searchin/std-proposals/string_view$20iterator/std-proposals/6X6_IjfzdYI/-Um3vQAZEwAJ</a> </li></ul><p> Sure you can wrap it it to cover your needs. You can have a look at that thread and follow some notes they've exposed. </p> <p> Thanks, </p> <p> Damian. </p> </description> <category>Ticket</category> </item> </channel> </rss>