Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
circle source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
Build 128
Build 129
Build 131
Latest
Options
Source code
#include <iostream> namespace ns1 { struct item_t { }; // This is found with ADL. void f(item_t) { std::cout<< "called ns1::f(item_t)\n"; } } namespace ns2 { void f(double) { std::cout<< "called ns2::f(double)\n"; } }; template<typename T> void f(T) { std::cout<< "called ::f({})\n".format(T~string); } void doit(auto callable, auto arg) { // Invoke the lifting lambda. // * If the lambda was formed with unqualified lookup, ADL is used to // find the candidate. Using-declarations encountered during unqualified // lookup may inject additional candidates for overload resolution. // * If the lamdba was formed with qualified lookup, ADL is not used. callable(arg); } int main() { // Make an ADL call to f. The argument type int has no associated // namespaces, so only ::f is a candidate. doit([]f, 1); // Make an ADL call to f. The argument type has ns1 as an associated // namespace. Both ::f and ns1::f are candidates, but ns1::f is the // better match. doit([]f, ns1::item_t{}); // Make a qualified call to f. The associated namespaces of item_t aren't // considered, because ADL only happens with unqualified lookup. doit([]::f, ns1::item_t{}); // Unqualified name lookup finds the alias-declaration for ns2::f. // This becomes one of the candidates, even though it's not a member of // an associated of the argument type double. This is exactly the // std::swap trick. using ns2::f; doit([]f, 3.14); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree