Skip to content

[fix] Use using declaration instead of directive to pull in std::swap.

Jö Fahlke requested to merge feature/fix-common-#55 into master

Closes: dune-common#55 (closed).

Fixup after dune-common!121 (merged)

C++11 §7.3.4 "Using directive":

A using-directive specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. During unqualified name lookup (3.4.1), the names appear as if they were declared in the nearest enclosing namespace which contains both the using-directive and the nominated namespace.

I.e. using namespace std; in a block scope makes it so that all names from std appear in the global namespace while inside that scope. Then, unqualified lookup for swap inside a block scope within namespace Dune::Alberta will search any enclosing scopes, and evetually the namespaces Dune::Alberta and Dune, where it finds Dune::swap. The unqualified lookup ends as soon as something was found, so the global namespace is not considered. Since unqualified lookup found a function declaration that was not a using declaration, ADL isn't even attempted.

Merge request reports