Follow

I would like to have a word with whoever was responsible for the filesystem library in C++. Iterator objects are from the devil.

en.cppreference.com/w/cpp/file

· · Web · 1 · 0 · 0

@xianc78
You take issue with instantiating a sentinel object for end iterator?

Otherwise I would think a range for listing directories would be extremely similar.

@john I'm just use to range listing and iterating like you do with arrays. I never liked the whole iterator pattern. It seemed like a waste.

@xianc78
"like you do with arrays"
I'm guessing you mean range-based for like

````
for ( auto dir_ent : dir.list() ) {
````
Yeah that would be fine and you could do that with a range.

But if you mean
````
for ( auto i = 0; i < dir_list.size(); ++i ) {
auto dir_ent = dir_list[i];
````
I have to think that's a bad idea. Think about what it would be like to implement dir_list in terms of `readdir` without allocating memory and scanning through the whole thing copying it over ahead of time.

Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.