Why are some parts of the C++ standard library (and it seems like in more recent standards it is getting more common) not directly in the ::std
namespace, but rather in a nested namespace? std::chrono
and std::filesystem
are two examples that pop to mind.
The obvious reason is the same as for any other project: there would be name collisions without it. For example, std::filesystem::copy
vs. std::copy
.
This isn't a complete explanation though, because
std::chrono
namespaceMore convincingly,
Note that (as Default points out in a comment), the regex library chooses consistency with Boost over namespace best practice, so it seems like #1 is more important. The same is true for std::thread
etc.
Separating the factual from the speculative and hypothetical:
Conclusion: the namespace structure was chosen for consistency with Boost, rather than consistency with the rest of the standard library or even among the libraries added in C++11.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With