<div dir="ltr"><div dir="ltr"><div dir="ltr">On Tue, Aug 27, 2019 at 7:53 AM Niall Douglas via Lib-Ext <<a href="mailto:lib-ext@lists.isocpp.org">lib-ext@lists.isocpp.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">On 26/08/2019 22:32, David Stone wrote:<br>
> I have several times written (and seen written) code like<br>
> <br>
> auto directory = std::filesystem::path(...);<br>
> for (auto const & path : directory) {<br>
> use(path);<br>
> }<br>
> <br>
> when what I meant was<br>
> <br>
> auto directory = std::filesystem::path(...);<br>
> for (auto path_it = std::filesystem::directory_iterator(directory);<br>
> path_it != std::filesystem::directory_iterator(); ++path_it) {<br>
> use(*path_it);<br>
> }<br>
<br>
I'd have some sympathy for you if you had written:<br>
<br>
auto directory = std::filesystem::path(...);<br>
for (auto const & path : *directory) {<br>
use(path);<br>
}<br>
<br>
... and you did not get directory enumeration, as it would be reasonable<br>
to expect dereferencing a path might do something like contents enumeration.<br>
<br>
But if you iterate a container of X, you expect to yield X.</blockquote><div><br></div><div>Well, I can see the logic for someone naively assuming that "/usr/local" would be a 'container' holding "/usr/local/include", "/usr/local/bin", "/usr/local/lib", and so on. That's <i><b>very roughly</b></i> what happens at the filesystem level when you do an `ls`. It wouldn't be very "C++-ish" to design the actual class type that way, but a naive user by definition doesn't know that.</div><div><br></div><div>A user who has worked in C++ for a while, and knows that C++ treats paths essentially as strings, might naively assume that "/usr/local" was a string-style 'container' holding '/', 'u', 's', 'r', '/', 'l', 'o', 'c', 'a', and 'l'. (They might even verify that `path::value_type` is a character type. It is.) As you say, for historical reasons that's not what the Committee gave us; but a user who merely <i><b>uses</b></i> C++ by definition doesn't know committee political history.</div><div><br></div><div>Any user is surprised (the first time) when "/usr/local" turns out to be a 'container' holding the meaningless fragments "/", "usr", and "local".</div><div><br></div><div>–Arthur<br></div></div></div></div>