C++17 Filesystem – Writing a simple file watcher
solarianprogrammer.com
solarianprogrammer.com
When you do that kind of stuff, keep in mind that many programs modify files by writing to a temp file and then renaming that file.
On a secondary note, "modern C++" needs to be stopped. This is absurd:
std::chrono::duration<int, std::milli>
Just say no. Don't include stuff like <chrono> or <functional>. Ignore Bjarne's opinions. Don't read books by Scott Meyers. Being effective with C++ means understanding its "powers" and then not using them.
The code has sleep calls and polls the filesystem. The nonportable OS support will actually block and have the kernel wake you up when there are actual changes - and not wake you when there is no change - much kinder on the CPU!
Just say no indeed, to polling the filesystem with sleep calls. (Maybe as a last resort if the OS specific support is unavailable?)
[0] https://github.com/sol-prog/cpp17-filewatcher/blob/master/Fi...
The vast majority of C++ users think that the using-directive is injecting names into the scope where it’s declared. ... In reality, the names are injected into the nearest common ancestor of the target namespace (::testing) and the usage namespace (::totw::example::anomymous). In our example, that’s the global namespace!
https://en.cppreference.com/w/cpp/container/unordered_map/co...