Skip to content

Commit 9ca1759

Browse files
authored
Merge pull request #3397 from eseiler/fix/benchmark2
fix: benchmark workaround
2 parents a4d9059 + 515ad28 commit 9ca1759

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

test/include/seqan3/test/compatibility/benchmark.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,20 @@
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
@@ -83,9 +91,7 @@
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
98104
namespace
99105
{
100106

101-
using namespace benchmark;
102107
using namespace benchmark::internal;
103-
using Benchmark = Benchmark;
104108

105109
} // namespace
106110

0 commit comments

Comments
 (0)