Add your own alias to std::chrono
, external to std
:
namespace chrono = std::chrono;
And then use chrono::milliseconds
.
It's possible to collapse layers of namespaces by adding an internal namespace alias. The standard library does this:
namespace std {
namespace ranges::views { /* views stuff */ }
namespace views = ranges::views;
}
So that std::ranges::views::filter
can also be accesses as std::views::filter
.
But that doesn't help here because milliseconds
is a type, not a namespace. The only way to collapse the contents of a namespace is with a using-directive (or equivalently, a whole lot of using-declarations):
namespace std {
namespace chrono { /* chrono things */ }
using namespace chrono;
}
Which isn't really a good idea because it could just break name lookup for things - especially if anything in std::chrono
is named the same as something in std
. This also completely defeats the purpose of having the nested namespace to begin with.
So the equivalent to the inner namespace alias would just be the outer namespace alias:
namespace std {
namespace chrono { /* chrono things */ }
}
namespace chrono = std::chrono;
And now you write chrono::milliseconds
instead of std::chrono::milliseconds
, without having to break anything in any of those namespaces.
Alternatively, if you really want to just shove everything into the same namespace, do it into a different one:
namespace all {
using namespace std;
using namespace std::chrono;
}
Although, as I said, questionable.
std
, so no. You can shorten namespaces with an alias though. – cigien May 7 '20 at 0:39namespace std { using namespace chrono; }
will that work? – nowi May 7 '20 at 0:52