6969 * ```
7070 *
7171 * ### Version 2
72- * https://godbolt.org/z/1M9f8fojv
72+ * https://godbolt.org/z/6ccEYY7hY
7373 *
74- * We use an anonymous namespace within `benchmark` to resolve `Benchmark` from either location without triggering
75- * deprecation warnings. The anonymous namespace brings both `benchmark` and `benchmark::internal` into scope, then
76- * aliases the first available `Benchmark` type. This works for both old and new versions and is future-proof, albeit
77- * harder to grasp (both code and intention).
74+ * We use an anonymous namespace within `benchmark` that imports `benchmark::internal` via a using-directive.
75+ * This brings the `Benchmark` class into scope without directly referencing it, allowing it to resolve from either
76+ * `benchmark::internal::Benchmark` (old versions) or `benchmark::Benchmark` (new versions) without triggering
77+ * deprecation warnings. This approach is future-proof, albeit harder to grasp (both code and intention).
78+ *
79+ * The anonymous namespace limits the effect of `using namespace` to the current file only. It gives the imported
80+ * names internal linkage (conceptually).
81+ * Without the anonymous namespace, it pollutes the benchmark namespace for everyone who includes this file. It has
82+ * external visibility.
83+ *
84+ * When the new version looks up `benchmark::Benchmark`, the declaration in the direct namespace (`benchmark`) has
85+ * precedence over the names introduced via the anonymous namespace.
7886 *
7987 * ```cpp
8088 * namespace benchmark
8391 * namespace
8492 * {
8593 *
86- * using namespace benchmark;
8794 * using namespace benchmark::internal;
88- * using Benchmark = Benchmark;
8995 *
9096 * }
9197 *
@@ -98,9 +104,7 @@ namespace benchmark
98104namespace
99105{
100106
101- using namespace benchmark ;
102107using namespace benchmark ::internal;
103- using Benchmark = Benchmark;
104108
105109} // namespace
106110
0 commit comments