Boost C++ Libraries: Ticket #11684: boost::string_ref lack of move constructor prevents efficient use in some stl containers https://svn.boost.org/trac10/ticket/11684 <p> Not quite sure if this is a bug or a feature request given the statement in the docs: </p> <p> "string_ref does not define a move constructor nor a move-assignment operator because copying a string_ref is just a cheap as moving one." </p> <p> While that line makes total sense on it's own, it does have some undesirable (for me at least) consequences. </p> <p> It means that and class that may want to have <code>string_ref</code>s as members also can't be trivially move constructible even if their other members are expensive to copy. </p> <p> For custom classes that can be worked around by defining a move constructor that copies the <code>string_ref</code> members and moves the rest. But it's a limitation that can't be easily worked around for things like <code>std::pair</code> or <code>std::tuple</code> since even if you try specialising those templates, you can't redefine the explicitly defaulted move constructor. </p> <p> This is especially an issue for using <code>string_ref</code> as a key or value type in an associative container - in this case the <code>std::pair</code> type MUST be copied during insertion. If the other type in the pair is expensive to copy then <code>string_ref</code>s lack of move construction becomes an annoying performance barrier. </p> <p> Workarounds exist so it's hardly high priority, but it does reduce the reusability of <code>string_ref</code> and cause there to be cases where an alternative implementation might be used for essentially the same purpose to work around this issue. the cost of adding move construction seem low to me even if it might result in uninformed users using it spuriously under the assumption it will provide some performance increase over copying. </p> <p> To be clear the request is: <strong>please consider adding move constructor/assignment to</strong> <code>boost::string_ref</code>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11684 Trac 1.4.3 anonymous Fri, 25 Sep 2015 12:57:04 GMT summary changed https://svn.boost.org/trac10/ticket/11684#comment:1 https://svn.boost.org/trac10/ticket/11684#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">boost::string_ref lack of move constructor prevents efficient use in std::map</span> → <span class="trac-field-new">boost::string_ref lack of move constructor prevents efficient use in some stl containers</span> </li> </ul> Ticket Marshall Clow Wed, 27 Jul 2016 17:05:22 GMT <link>https://svn.boost.org/trac10/ticket/11684#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11684#comment:2</guid> <description> <p> I'm confused. I tried this: </p> <pre class="wiki">struct S { std::string_view sv; }; int main () { static_assert( std::is_trivially_move_constructible&lt;std::string_view&gt;::value, "" ); static_assert( std::is_trivially_move_constructible&lt;S&gt;::value, "" ); static_assert( std::is_trivially_constructible&lt;std::string_view, std::string_view&amp;&amp;&gt;::value, "" ); } </pre><p> and it compiled w/o error. (clang, libc++) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 27 Jul 2016 17:08:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11684#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11684#comment:3</guid> <description> <p> My bad. Just tried again with boost::string_ref, and I see what's up. Looking into it... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 27 Jul 2016 17:48:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11684#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11684#comment:4</guid> <description> <p> I don't think that adding move ctor/assignment to <code>string_ref</code> will help. To be "trivial', they have to be defaulted. If the copy ctor/assignment is defaulted, that's sufficient. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 27 Jul 2016 18:21:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11684#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11684#comment:5</guid> <description> <p> Commit c56dd13592daa332a74b90aeca8724c5b3cc3d5d should take care of this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 13 Feb 2017 18:34:40 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11684#comment:6 https://svn.boost.org/trac10/ticket/11684#comment:6 <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">fixed</span> </li> </ul> Ticket