Boost C++ Libraries: Ticket #7021: filesystem::path::has_filename() is wrong https://svn.boost.org/trac10/ticket/7021 <p> in filesystem/v3/path.hpp : </p> <blockquote> <p> bool has_filename() const { return !m_pathname.empty(); } </p> </blockquote> <p> should be (according to docs): </p> <blockquote> <p> bool has_filename() const { return !filename().empty(); } </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7021 Trac 1.4.3 Craig Dickson <cdickson@…> Tue, 30 Oct 2012 15:09:13 GMT <link>https://svn.boost.org/trac10/ticket/7021#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7021#comment:1</guid> <description> <p> Theoretically, yes, it makes sense that has_filename() would return true if filename() returns a non-empty string. However, in practice, I think the way it's written will produce the same result. According to the path decomposition table in the filesystem docs, the only time filename() returns an empty string is when m_pathname is empty. That being the case, has_filename() should return true if m_pathname is not empty, and testing m_pathname.empty() is faster than testing filename().empty() in most cases. </p> <p> On the other hand, I have a fundamental disagreement with the way path decomposes a path that ends with a slash, which is relevant here because a path ending with a slash should have no filename (path currently infers an invisible "." at the end). I'll file that concern as a separate bug, though, because it's tangential to this one. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Tue, 30 Dec 2014 20:43:46 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7021#comment:2 https://svn.boost.org/trac10/ticket/7021#comment:2 <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> <p> Craig Dickson's comment is correct. !m_pathname.empty() is equivalent to !filename().empty(). </p> <p> It is editorially better to document a result in terms of a public function than by referring to a private member, while an implementation is free to use the private member. It might be a bit cleaner if the implementation exactly follows the formulation in the spec, but that relies on the compiler to actually inline the function call or is less efficient. </p> <p> Thanks for your interest in boost.filesystem, </p> <p> --Beman </p> Ticket