[boost][filesystem] re-assign a recursive_directory_iterator
Hi, should it be possible to re-assign a filesystem::recursive_directory_iterator? I tried something like the following (could strip out my code and build a small test case if needed but this would take some time): fs::path aPath = ...; // assign to some valid path const fs::recursive_directory_iterator initial(path); const fs::recursive_directory_iterator end(); fs::recursive_directory_iterator current(path); // now increment current and do something with it (traverse directories etc). // ... // Later I want to go back to initial position with: current = initial; // but this causes a crash later when traversing again, seems that the (current == end) check gives wrong results and I dereference invalid current // I tried also the following: current = fs::recursive_directory_iterator(path); // this doesn't crash but (current == end) seems to give also wrong results I don't want to create 'current' as a temporary, so constructing a new 'current' when needed. In my case it is a class member. Anyhow, I can implement a workaround for me. Is it a bug or is it not wanted to re-assign the iterator? If it is not wanted to re-assign, maybe the assignment operator should be disabled? Thanks in advance, Sascha
AMDG Sascha Ochsenknecht wrote:
should it be possible to re-assign a filesystem::recursive_directory_iterator? I tried something like the following (could strip out my code and build a small test case if needed but this would take some time):
fs::path aPath = ...; // assign to some valid path
const fs::recursive_directory_iterator initial(path); const fs::recursive_directory_iterator end(); fs::recursive_directory_iterator current(path);
// now increment current and do something with it (traverse directories etc). // ...
// Later I want to go back to initial position with: current = initial; <snip>
The state is shared between all copies of a recursive_directory_iterator. You can make it work by storing the path and creating a new iterator when you want to reset. current = recursive_directory_iterator(aPath); In Christ, Steven Watanabe
participants (2)
-
Sascha Ochsenknecht
-
Steven Watanabe