Boost C++ Libraries: Ticket #6874: Path should have a size() member function https://svn.boost.org/trac10/ticket/6874 <p> It would be convenient for filesystem::path to provide a size() member function, especially for circumstances that require interface with legacy windows apps and functions. </p> <p> Consider the traditional windows path buffer: </p> <pre class="wiki">wchar_t legacy [_MAX_PATH]; </pre><p> and a boost path: </p> <pre class="wiki">boost::filesystem::path path = L"&lt;...&gt;"; </pre><p> In order to ensure that buffer overruns do not occur when copying into a legacy buffer, assuming that querying the size of the wstring() member function is the same as the c_str() size, code similar to the following is required: </p> <pre class="wiki">if (path.wstring().size()+1 &lt;= _MAX_PATH) { wcscpy(&amp;legacy[0], path.c_str()); } else { // buffer would overrun, do something else ... } </pre><p> It would be more convenient, and arguably safer, if filesystem::path provides the size of the string that is referenced by the c_str() function. </p> <pre class="wiki">if (path.size()+1 &lt;= _MAX_PATH) { wcscpy(&amp;legacy[0], path.c_str()); } else { // buffer would overrun, do something else ... } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6874 Trac 1.4.3 Beman Dawes Tue, 08 Sep 2015 20:53:28 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6874#comment:1 https://svn.boost.org/trac10/ticket/6874#comment:1 <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> <p> I've wished for this several times, too. </p> <p> My only concern was that there might be confusion with the number of elements that would be found if the path were iterated over. That concern didn't seem serious enough to derail the proposal. </p> <p> Thanks, </p> <p> --Beman </p> Ticket Michel Morin Wed, 09 Sep 2015 03:32:54 GMT <link>https://svn.boost.org/trac10/ticket/6874#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6874#comment:2</guid> <description> <blockquote class="citation"> <p> My only concern was that there might be confusion with the number of elements that would be found if the path were iterated over. </p> </blockquote> <p> Then, how about renaming to <code>length</code>? (... well, <code>std::string</code> has both <code>size</code> and <code>length</code> member functions.) </p> <p> &lt;/bikeshed&gt; </p> </description> <category>Ticket</category> </item> </channel> </rss>