2

Suppose I have an outer namespace, and inside that namespace, I have an inner namespace std. Is this allowed or forbidden by the standard?

namespace outer {
    namespace std {
        // custom implementation
    }
}

I understand it’s probably considered poor practice or something, but I’m just trying to understand why C++ stl implementations always define _STD = ::std. Is it because someone theoretically could do using namespace outer::std? I’d figure that it would be forbidden by the standard.

More importantly, in my code, should I use ::std?

  • 1
    `using namespace outer` would make `std` ambiguous if any standard headers were included. But `::std` isn't ambiguous. Never seen anyone use ::std most only use std. You only need to use ::std to avoid ambiguity. But just don't define outer::std and that's enough! – QuentinUK Jun 07 '20 at 09:09

0 Answers0