Created
December 15, 2014 12:10
-
-
Save anders-sjogren/4cfea1017ac2620732f7 to your computer and use it in GitHub Desktop.
Code showing the difference in lookup behaviour for functions and callable objects, in connection to argument-dependent lookup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
namespace adl_ns { | |
struct X{}; | |
std::string f(const X&){return "f from ADL namespace";} | |
std::string g(const X&){return "g from ADL namespace";} | |
} | |
namespace using_ns { | |
template<class T> | |
std::string f(const T&){ | |
return "f from using namespace"; | |
} | |
struct G { | |
constexpr G() = default; | |
template<class T> | |
constexpr std::string operator()(const T&) { | |
return "g from using namespace"; | |
} | |
}; | |
constexpr G g{}; | |
} | |
int main() | |
{ | |
using namespace using_ns; | |
adl_ns::X x; | |
std::cout << f(x) << std::endl; | |
std::cout << g(x) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment