I like all of this.
> Also the trailing //
> namespace N1 is omitted because it seems redundant for such a small
> enclosing block.
I’d probably leave it in anyway. I’d certainly leave it in if there
were multiple levels of namespacing.
> The only situation that causes turmoil here is when you have:
[snip]
> Note that N0 is sorted after N1, and D before C, but that's because N0 is
> the "main" namespace in the file. This doesn't bother me though.
> Thoughts?
This doesn’t bother me either. In fact, you presumably included
forward declarations in N1 because you needed to use them in this
file, and it’s likely that you needed them somewhere in N0, so they
necessarily must precede N0. For example, you might have had a
constructor N0::C::C(N1::A* a).
When I’m working with forward declarations, I always try to put all of
them at the top of the file, immediately following the header
#includes. Whether or not namespaces are in play doesn’t seem
relevant. Forward declarations first, then “meat.” If all of your
meat’s in N0, so be it.
With that in mind, I might revise your example slightly:
namespace N0 {
class D;
} // namespace N0
namespace N1 {
class A;
class B;
} // namespace N1
namespace N0 {
class C {
// ...
private:
N1::A* a_;
N1::B* b_;
D* d_;
};
} // namespace N0
Nothing wrong with opening, then closing, and then reopening the same
namespace multiple times, even with other stuff in between.
Thoughts?
We just went through this with header #includes too in the past month.
We agreed on “put all of the platform #includes after the non-platform
ones.” I think we can do the same for forward declarations.
I'm not sure I can automatically enforce the order in a clang plugin though.
-- Elliot
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
> Also the trailing //> namespace N1 is omitted because it seems redundant for such a smallI’d probably leave it in anyway. I’d certainly leave it in if there
> enclosing block.
were multiple levels of namespacing.
That’s fine with me.
Can we update the style guide [1] to reflect this decision? There's no
point in commenting the namespace's end brace when the content of the
namespace is only 1 or 2 lines long.
[1] https://sites.google.com/a/chromium.org/dev/developers/coding-style